about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-20 00:23:52 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-20 00:23:52 +0000
commit6e07ca9107a58af6a2fd8ba534f84019fc5a1114 (patch)
tree2d2c74ad872206e8a29b9b8d4055215d5726fcb7
parent808e6c6269c6f83675273d7bd5a2998a09637e3f (diff)
downloadyahns-6e07ca9107a58af6a2fd8ba534f84019fc5a1114.tar.gz
The closed IO may not immediately register to all threads due
to ordering problems
-rw-r--r--lib/yahns/acceptor.rb3
-rw-r--r--lib/yahns/queue_epoll.rb3
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/yahns/acceptor.rb b/lib/yahns/acceptor.rb
index 43d5fe8..888e4b6 100644
--- a/lib/yahns/acceptor.rb
+++ b/lib/yahns/acceptor.rb
@@ -21,7 +21,8 @@ module Yahns::Acceptor # :nodoc:
         queue.fdmap.desperate_expire_for(self, 5)
         sleep 1 # let other threads do some work
       rescue => e
-        break if closed?
+        # sleep since this check is racy (and uncommon)
+        break if closed? || (sleep(0.01) && closed?)
         Yahns::Log.exception(logger, "accept loop", e)
       end while true
     end
diff --git a/lib/yahns/queue_epoll.rb b/lib/yahns/queue_epoll.rb
index 1813581..7df1cc0 100644
--- a/lib/yahns/queue_epoll.rb
+++ b/lib/yahns/queue_epoll.rb
@@ -46,7 +46,8 @@ class Yahns::Queue < SleepyPenguin::Epoll::IO # :nodoc:
           end
         end
       rescue => e
-        break if closed?
+        # sleep since this check is racy (and uncommon)
+        break if closed? || (sleep(0.01) && closed?)
         Yahns::Log.exception(logger, 'queue loop', e)
       end while true
     end