about summary refs log tree commit homepage
path: root/lib/rainbows/thread_spawn.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-29 12:59:01 -0800
committerEric Wong <normalperson@yhbt.net>2009-12-29 12:59:01 -0800
commit31ee6b4daa1da9cd02e75b27924b2729345e999d (patch)
treec00cc159a7e330763ae72f307dab3664d0f3d5b9 /lib/rainbows/thread_spawn.rb
parentd5375f5c24abfae0173007f47bc9e83139d556b5 (diff)
downloadrainbows-31ee6b4daa1da9cd02e75b27924b2729345e999d.tar.gz
Under all MRI 1.8, a blocking Socket#accept Ruby method (needs
to[1]) translate to a non-blocking accept(2) system call that may
wake up threads/processes unnecessarily.  Unfortunately, we
failed to trap and ignore EAGAIN in those cases.

This issue did not affect Ruby 1.9 running under modern Linux
kernels where a _blocking_ accept(2) system call is not (easily,
at least) susceptible to spurious wakeups.  Non-Linux systems
running Ruby 1.9 may be affected.

[1] - using a blocking accept(2) on a shared socket with
      green threads is dangerous, as noted in
      commit ee7fe220ccbc991e1e7cbe982caf48e3303274c7
      (and commit 451ca6997b4f298b436605b7f0af75f369320425)
Diffstat (limited to 'lib/rainbows/thread_spawn.rb')
-rw-r--r--lib/rainbows/thread_spawn.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb
index eb3ca75..75cc150 100644
--- a/lib/rainbows/thread_spawn.rb
+++ b/lib/rainbows/thread_spawn.rb
@@ -34,8 +34,8 @@ module Rainbows
               # unlikely one.  Since this case is (or should be) uncommon,
               # just busy wait when we have to.
               sleep(0.01)
-            else
-              klass.new(l.accept) do |c|
+            elsif c = Rainbows.sync_accept(l)
+              klass.new(c) do |c|
                 begin
                   lock.synchronize { G.cur += 1 }
                   process_client(c)
@@ -44,7 +44,6 @@ module Rainbows
                 end
               end
             end
-          rescue Errno::EINTR, Errno::ECONNABORTED
           rescue => e
             Error.listen_loop(e)
           end while G.alive