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

Uncaught RuntimeError: eventmachine not initialized: evma_set_pending_connect_timeout #22

Closed
loren opened this issue Nov 14, 2013 · 3 comments

Comments

@loren
Copy link

loren commented Nov 14, 2013

Every so often, we get this RuntimeError when calling publish_async due to some as-yet unknown issue we're having with EventMachine+Passenger:

/gems/eventmachine-1.0.3/lib/em/connection.rb:619 in "set_pending_connect_timeout"
/gems/eventmachine-1.0.3/lib/em/connection.rb:619 in "pending_connect_timeout="
/gems/em-http-request-1.0.3/lib/em-http/http_connection.rb:61 in "block in activate_connection"
/gems/eventmachine-1.0.3/lib/eventmachine.rb:672 in "bind_connect"
/gems/em-http-request-1.0.3/lib/em-http/http_connection.rb:54 in "activate_connection"
/gems/em-http-request-1.0.3/lib/em-http/http_connection.rb:89 in "setup_request"
/gems/em-http-request-1.0.3/lib/em-http/http_connection.rb:8 in "post"
/gems/keen-0.7.7/lib/keen/http.rb:75 in "post"
/gems/keen-0.7.7/lib/keen/client/publishing_methods.rb:69 in "publish_async"

Sometimes the EM problem causes an error that the Keen gem catches and bubbles up as a Keen::Error:

Keen::Error: Keen IO Exception: An EventMachine loop must be running to use publish_async calls
/gems/keen-0.7.7/lib/keen/http.rb:53 in "initialize"
/gems/keen-0.7.7/lib/keen/client/publishing_methods.rb:66 in "new"
/gems/keen-0.7.7/lib/keen/client/publishing_methods.rb:66 in "publish_async"

I'd rather just catch the Keen::Error in my application code and not have to look out for the RuntimeError, too.

@joshed-io
Copy link
Contributor

@loren - thanks for opening the issue. There are rare cases where the EventMachine will die even if the process is still running. Since you've seen this in your app, I suggest adding some protection like this:

def ensure_em
  unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
    Thread.new { EventMachine.run }
    sleep 1
  end
end

# put this before calls
ensure_em
Keen.publish_async(...)

This ensures that the loop is running before making the call. Alternatively you could catch the exception, restart em, and then try the call again. I'll look into the RuntimeError bubbling up, that's strange. Maybe a race condition.

Also see - https://gist.github.com/jonkgrimes/5103321

@joshed-io
Copy link
Contributor

That EM check should fix this bug, closing until we see it again.

@songyiyang
Copy link

This works, thanks!

jordanmichaelrushing pushed a commit to jordanmichaelrushing/actioncable that referenced this issue Nov 17, 2015
Adding in a runtime error catch for Event Machine for the very rare chance that the Event Machine isn't running or stopped running.

Code taken from keenlabs/keen-gem#22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants