From 41d9de49f9adf49b50b034ece6ea5a58688a6cce Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 2 Aug 2010 04:52:21 +0000 Subject: event_machine: protect IO#close from EBADF 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. --- lib/rainbows/event_machine.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/rainbows/event_machine.rb') 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 end end -- cgit v1.2.3-24-ge0c7