eventmachine not initialized: evma_signal_loopbreak #756
Description
I am running EventMachine as part of an RSpec test suite, see https://github.com/ably/ably-ruby/blob/master/spec/support/event_machine_helper.rb for the somewhat hacky way to replace the test block with a block that runs a reactor and yields to the test block. This is convenient because one can simply tag a test / context with :event_machine
(such as https://github.com/ably/ably-ruby/blob/master/spec/acceptance/realtime/auth_spec.rb#L7), and it all just works.
However, I have found that I can consistently get EM into a state where it raises an exception when starting the reactor:
RuntimeError:
eventmachine not initialized: evma_signal_loopbreak
# /Users/mattheworiordan/.rvm/gems/ruby-2.2.5/gems/eventmachine-1.2.1/lib/eventmachine.rb:1133:in `signal_loopbreak'
# /Users/mattheworiordan/.rvm/gems/ruby-2.2.5/gems/eventmachine-1.2.1/lib/eventmachine.rb:1133:in `next_tick'
# ./lib/ably/realtime/connection/connection_manager.rb:31:in `initialize'
Now when I catch that exception and run a pry
at that point, I get some odd results:
[1] pry(RSpec::EventMachine)> e
=> #<RuntimeError: eventmachine not initialized: evma_signal_loopbreak>
[2] pry(RSpec::EventMachine)> ::EventMachine.reactor_running?
=> true
[3] pry(RSpec::EventMachine)> ::EventMachine.stop
RuntimeError: eventmachine not initialized: evma_stop_machine
from (pry):4:in `stop'
[4] pry(RSpec::EventMachine)> ::EventMachine.stopping?
RuntimeError: eventmachine not initialized: evma_stopping
from (pry):5:in `stopping?'
[5] pry(RSpec::EventMachine)> EM.next_tick { puts "a" }
RuntimeError: eventmachine not initialized: evma_signal_loopbreak
from /Users/mattheworiordan/.rvm/gems/ruby-2.2.5/gems/eventmachine-1.2.1/lib/eventmachine.rb:1133:in `signal_loopbreak'
So it thinks it is running, yet it's raised a eventmachine not initialized: evma_signal_loopbreak
exception when accessing any EM feature. If I try and stop EM it tells me it's not running.
From this point forwards my test suite fails unilaterally as there is no way to resurrect or kill EM completely.
I have tried all sorts of permutations to get this fixed such as spawning threads, explicitly killing the reactor even though I know it's terminated at the end of each test, and nothing I do seems to help.
I am on OS X, Ruby 2.2.1 and 2.2.5, and have upgraded to the latest EM 1.2.1 as well.
Any advice on what I could do would be appreciated.