Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event machine not initialized exception #27

Open
rhettc opened this issue Apr 2, 2014 · 2 comments
Open

event machine not initialized exception #27

rhettc opened this issue Apr 2, 2014 · 2 comments

Comments

@rhettc
Copy link

rhettc commented Apr 2, 2014

Backstory

I am implementing the PubNub gem in my Rails app. I use ActiveRecord callbacks as a hook to publish events when a model is created/updated/destroyed/etc. So I've been using the Rails console extensively as I develop to chain together a series of statements that create a variety of model instances, save them and then I monitor the PubNub dev console for my published event (the PubNub dev console is very helpful, btw).

pubnub gem 3.5.1
Rails/Puma

Issue

Sometimes when publishing a message I would get an exception noting that the Event Machine hadn't started.

eventmachine not initialized: evma_install_oneshot_timer

The same set of statements would sometimes result in the exception, sometimes not. Based on some quick research and a bit of conjecture, it seems that the first publish invocation would prompt EM to start, but before it completed initializing, another publish invocation occurs and results in the exception. Like I said, just speculation on my part.

Fix/Workaround

Based on a search of the error message, I came across a fix where as soon as you start EM, have that thread wait until EM is up and running before continuing. I put this in a rails initializer and I haven't had the problem since. Cheers

Thread.new { EM.run } unless EM.reactor_running?
Thread.pass until EM.reactor_running?
@geremyCohen
Copy link
Contributor

@rhettc Very cool! Thanks, we'll be sure to document this!

@blazeroot
Copy link
Contributor

@rhettc thanks for providing example fix! I see now i lost one line while refactoring from 3.4, i think it won't be necessary to include that in rails initializer (after adding that lost line), but i have to made some tests. I will keep you informed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants