about summary refs log tree commit homepage
path: root/lib/rainbows/event_machine.rb
diff options
authorEric Wong <normalperson@yhbt.net>2010-08-02 04:52:21 +0000
committerEric Wong <normalperson@yhbt.net>2010-08-02 04:52:21 +0000
commit41d9de49f9adf49b50b034ece6ea5a58688a6cce (patch)
tree19f36d92cbcc03afcd434dbaa5e609d148225dda /lib/rainbows/event_machine.rb
parent3a96720e4e0f1d14599b9fae10e210110976e0c5 (diff)
EventMachine may close the underlying file descriptor on us if
there are unrecoverable errors during write.  So IO#closed? is
a pointless check because EM does not invalidate the underlying
file descriptor.
Diffstat (limited to 'lib/rainbows/event_machine.rb')
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index 757817d..a0b9ca6 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -157,7 +157,14 @@ module Rainbows
       def unbind
         async_close = @env[ASYNC_CLOSE] and async_close.succeed
         @body.respond_to?(:fail) and @body.fail
-        @_io.close unless @_io.closed?
+        begin
+          @_io.close
+        rescue Errno::EBADF
+          # EventMachine's EventableDescriptor::Close() may close
+          # the underlying file descriptor without invalidating the
+          # associated IO object on errors, so @_io.closed? isn't
+          # sufficient.
+        end