Permalink
Browse files

Use non-blocking reads/writes for signal pipe

Without this fix the signal handler could block on #syswrite when the
reader wasn't fast enough. Because the pipe is only used to signal the
EM thread, we don't mind a writing failing because the buffer is full.

Change-Id: I2474a38c3d78b96be63d2ee7aac239da79c34cc5
  • Loading branch information...
1 parent 996e2f3 commit 2f45a7ff9d82896704d12e3d37a7379fe2d80375 @pietern pietern committed Oct 18, 2012
Showing with 11 additions and 3 deletions.
  1. +10 −2 em-posix-spawn/lib/em/posix/spawn/child.rb
  2. +1 −1 em-posix-spawn/lib/em/posix/spawn/version.rb
@@ -136,7 +136,11 @@ def setup!
@notifier.notify_readable = true
@prev_handler = ::Signal.trap(:CHLD) do
- @pipe[1].syswrite("x")
+ begin
+ @pipe[1].write_nonblock("x")
+ rescue IO::WaitWritable
+ end
+
@prev_handler.call
end
@@ -178,7 +182,11 @@ def initialize(handler)
end
def notify_readable
- @io.sysread(1)
+ begin
+ @io.read_nonblock(65536)
+ rescue IO::WaitReadable
+ end
+
@handler.signal
end
end
@@ -1,7 +1,7 @@
module EventMachine
module POSIX
module Spawn
- VERSION = "0.1.5"
+ VERSION = "0.1.6"
end
end
end

0 comments on commit 2f45a7f

Please sign in to comment.