about summary refs log tree commit homepage
path: root/lib/yahns/server.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-10-21 21:23:21 +0000
committerEric Wong <e@80x24.org>2013-10-21 21:39:06 +0000
commitda3d424523e29dff597f272eda5162ac7c53f846 (patch)
treecc3afacdba033f9ca9851964d9012ec505c53434 /lib/yahns/server.rb
parent0b95ed6477e89f252df3006310c96c666e7496da (diff)
downloadyahns-da3d424523e29dff597f272eda5162ac7c53f846.tar.gz
This seems problematic on rbx (and their bugtracker requiring access
to a non-Free SaaS is an inconvenience to me).  Also, improve
the robustness of our acceptors in case by rescuing Thread#join
as well.
Diffstat (limited to 'lib/yahns/server.rb')
-rw-r--r--lib/yahns/server.rb31
1 files changed, 22 insertions, 9 deletions
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index 3ba7537..b66d208 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -359,16 +359,29 @@ class Yahns::Server # :nodoc:
     alive
   end
 
+  # return true if any acceptor is still alive, false otherwise
   def acceptors_alive
-    @athr.delete_if do |t|
-      # blocking accept() does not wake up on, close() only EINTR and
-      # new connections.  So Thread#run will send SIGVTALRM via
-      # pthread_kill, which will break it out of blocking syscalls
-      # like accept()
-      # if t.run fails, thread is dead
-      t.run rescue nil
-      t.join(1)
-    end.size > 0
+    case RUBY_ENGINE
+    when "rbx"
+      false # XXX this needs to be diagnosed and fixed for rbx
+    else
+      # We should stop acceptors before stopping queues.  Closing the
+      # acceptor socket is not sufficient to stop the last client of
+      # each thread fom being accepted and thrown into the queue.
+      @athr.delete_if do |t|
+        # blocking accept() does not wake up on, close() only EINTR and
+        # new connections.  So Thread#run will send SIGVTALRM via
+        # pthread_kill, which will break it out of blocking syscalls
+        # like accept()
+        t.run rescue nil # if .run fails, thread is dead and joinable
+        begin
+          t.join(0.1)
+        rescue => e
+          Yahns::Log.exception(@logger, "acceptor shutdown", e)
+          true
+        end
+      end.size > 0
+    end
   end
 
   # single-threaded only, this is overriden if @worker_processes is non-nil