Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix callbacks being lost when an error occurs in next_tick. Closes #185

  • Loading branch information...
commit 2ce9e5045520fbe8d72e222f3e47f833852728cf 1 parent 50502e6
@raggi raggi authored
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/eventmachine.rb
View
19 lib/eventmachine.rb
@@ -947,10 +947,21 @@ def self.run_deferred_callbacks
cback.call result if cback
end
- @next_tick_mutex.synchronize do
- jobs, @next_tick_queue = @next_tick_queue, []
- jobs
- end.each { |j| j.call }
+ # Capture the size at the start of this tick...
+ size = @next_tick_mutex.synchronize { @next_tick_queue.size }
+ size.times do |i|
+ callback = @next_tick_mutex.synchronize { @next_tick_queue.shift }
+ begin
+ callback.call
+ ensure
+ # This is a little nasty. The problem is, if an exception occurs during
+ # the callback, then we need to send a signal to the reactor to actually
+ # do some work during the next_tick. The only mechanism we have from the
+ # ruby side is next_tick itself, although ideally, we'd just drop a byte
+ # on the loopback descriptor.
+ EM.next_tick {}
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.