about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-15 00:01:32 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-15 00:05:40 +0000
commit20c0f28cf60f164c9788b694625bce22962464f3 (patch)
treefbef8ffa8d81b344bd4647066d301f9b745b60cb
parentddcea26976f24dda8a0cd65022065100bb40fbb7 (diff)
downloadunicorn-20c0f28cf60f164c9788b694625bce22962464f3.tar.gz
By avoid Array#each
-rw-r--r--lib/unicorn/http_server.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index f07a3fc..581471b 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -604,7 +604,7 @@ class Unicorn::HttpServer
     init_worker_process(worker)
     nr = 0 # this becomes negative if we need to reopen logs
     alive = worker.tmp # tmp is our lifeline to the master process
-    ready = LISTENERS
+    ready = LISTENERS.dup
 
     # closing anything we IO.select on will raise EBADF
     trap(:USR1) { nr = -65536; SELF_PIPE[0].close rescue nil }
@@ -627,7 +627,7 @@ class Unicorn::HttpServer
       # and before IO.select).
       alive.chmod(m = 0 == m ? 1 : 0)
 
-      ready.each do |sock|
+      while sock = ready.shift
         if client = sock.kgio_tryaccept
           process_client(client)
           nr += 1
@@ -640,7 +640,10 @@ class Unicorn::HttpServer
       # we're probably reasonably busy, so avoid calling select()
       # and do a speculative non-blocking accept() on ready listeners
       # before we sleep again in select().
-      redo unless nr == 0 # (nr < 0) => reopen logs
+      unless nr == 0 # (nr < 0) => reopen logs (unlikely)
+        ready = LISTENERS.dup
+        redo
+      end
 
       ppid == Process.ppid or return
       alive.chmod(m = 0 == m ? 1 : 0)
@@ -648,7 +651,7 @@ class Unicorn::HttpServer
       # timeout used so we can detect parent death:
       ret = IO.select(LISTENERS, nil, SELF_PIPE, timeout) and ready = ret[0]
     rescue Errno::EINTR
-      ready = LISTENERS
+      ready = LISTENERS.dup
     rescue Errno::EBADF
       nr < 0 or return
     rescue => e