Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Fix callbacks being lost when an error occurs in next_tick. Closes ev…
Browse files Browse the repository at this point in the history
  • Loading branch information
raggi committed Sep 29, 2011
1 parent 50502e6 commit 2ce9e50
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/eventmachine.rb
Expand Up @@ -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


Expand Down

0 comments on commit 2ce9e50

Please sign in to comment.