about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-02-09 23:32:59 -0800
committerEric Wong <normalperson@yhbt.net>2009-02-10 02:03:09 -0800
commit9e1e784bdd4cb51ddd14e2af1fb8cc78a0144416 (patch)
tree538924fcb579c93303d0882a1b9a536787284a21
parent61d8e20732030c9a43ea266373bc778413e49b47 (diff)
downloadunicorn-9e1e784bdd4cb51ddd14e2af1fb8cc78a0144416.tar.gz
* IO.pipe.map { } looks moronic, especially without
  doing more inside it (like setting set_cloexec).

* No need to sleep when we have an unhandled master
  loop exception (save for paranoia).

* client.class == TCPSocket is slightly more expensive
  than TCPSocket === client

* nilify client to avoid GC from trying to close it

* Process.kill => kill
-rw-r--r--lib/unicorn.rb15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 0c3419b..90c5d86 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -152,10 +152,8 @@ module Unicorn
     def join
       # this pipe is used to wake us up from select(2) in #join when signals
       # are trapped.  See trap_deferred
-      @rd_sig, @wr_sig = IO.pipe.map do |io|
-        io.nonblock = true
-        io
-      end unless (@rd_sig && @wr_sig)
+      @rd_sig, @wr_sig = IO.pipe unless (@rd_sig && @wr_sig)
+      @rd_sig.nonblock = @wr_sig.nonblock = true
 
       %w(QUIT INT TERM USR1 USR2 HUP).each { |sig| trap_deferred(sig) }
 
@@ -204,11 +202,10 @@ module Unicorn
       rescue Object => e
         logger.error "Unhandled master loop exception #{e.inspect}."
         logger.error e.backtrace.join("\n")
-        sleep 1 rescue nil
         retry
       end
       stop # gracefully shutdown all workers on our way out
-      logger.info "master pid=#{$$} exit"
+      logger.info "master pid=#{$$} join complete"
     end
 
     # Terminates all workers, but does not exit master process
@@ -389,6 +386,7 @@ module Unicorn
       tempfile = worker.tempfile
       alive = true
       ready = @listeners
+      client = nil
       %w(TERM INT).each { |sig| trap(sig) { exit(0) } } # instant shutdown
       trap('QUIT') do
         alive = false
@@ -416,7 +414,7 @@ module Unicorn
               end
               accepted = client.sync = true
               client.nonblock = false
-              set_client_sockopt(client) if client.class == TCPSocket
+              set_client_sockopt(client) if TCPSocket === client
               process_client(client)
             rescue Errno::ECONNABORTED
               # client closed the socket even before accept
@@ -426,6 +424,7 @@ module Unicorn
             end
             tempfile.chmod(nr += 1)
           end
+          client = nil
 
           # make the following bet: if we accepted clients this round,
           # we're probably reasonably busy, so avoid calling select(2)
@@ -458,7 +457,7 @@ module Unicorn
     # is no longer running.
     def kill_worker(signal, pid)
       begin
-        Process.kill(signal, pid)
+        kill(signal, pid)
       rescue Errno::ESRCH
         worker = @workers.delete(pid) and worker.tempfile.close rescue nil
       end