This code demonstrates the problem:
EM.error_handler do |e|
puts "Running error_handler"
puts "Raising RuntimeError"
puts "Running an independent tick event"
When run I'd expect it to output:
Running an independent tick event
Instead you get:
This is because both next_tick blocks are pulled of the @next_tick_queue in EventMachine.run_deferred_callbacks and run in an each loop. When the first one throws an exception the second one isn't given a chance to run.
This means it's impossible to reliably catch any exceptions that might be thrown in next_tick blocks without the possibility of impacting other next_tick or tick_loops that happen to be scheduled at around the same time.
Can you get a pull request going for this? It is kind of ridiculous that this is still broken.
Fix callbacks being lost when an error occurs in next_tick. Closes #185
There was a little bit of hairy in there, but I left a comment.