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

Getting EventMachine::ConnectionNotBound error with 0.2.10 #42

Closed
myronmarston opened this issue Aug 4, 2010 · 4 comments
Closed

Getting EventMachine::ConnectionNotBound error with 0.2.10 #42

myronmarston opened this issue Aug 4, 2010 · 4 comments

Comments

@myronmarston
Copy link

em_http_example.rb:

require 'rubygems'
gem 'em-http-request', '0.2.10'
require 'em-http'

def make_http_request(url)
  EventMachine.run do
    http = EventMachine::HttpRequest.new(url).get
    http.callback { EventMachine.stop; return http }
  end 
end

make_http_request("http://example.com/")

Output:

ruby-1.8.7-p299 ➜  ~  ruby em_http_example.rb 
/Users/mmarston/.rvm/gems/ruby-1.8.7-p299/gems/eventmachine-0.12.10/lib/eventmachine.rb:1425:in `event_callback': recieved ConnectionUnbound for an unknown signature: 2 (EventMachine::ConnectionNotBound)
        from /Users/mmarston/.rvm/gems/ruby-1.8.7-p299/gems/eventmachine-0.12.10/lib/eventmachine.rb:263:in `release_machine'
        from /Users/mmarston/.rvm/gems/ruby-1.8.7-p299/gems/eventmachine-0.12.10/lib/eventmachine.rb:263:in `run'
        from em_http_example.rb:6:in `make_http_request'
        from em_http_example.rb:12
@igrigorik
Copy link
Owner

Hmm, well I'm not sure that the code makes sense the way it is setup currently. You can't call return from a callback like that (unless I'm missing something at the moment). If you remove the return statement, everything will work just fine. If you need ~ blocking API, you should take a look at em-synchrony.

@myronmarston
Copy link
Author

I'm actually not using em-http-request in any of my projects; I just want to make sure VCR supports it. All of the other HTTP libraries supported by VCR are synchronous, and use the same shared specs, with each implementing #make_http_request differently based on the libraries API, so I wrote the em-http-request implementation of #make_http_request to be synchronous, even though you would never use it that way.

Using return in a block is a bit counterintuitive, but it's standard ruby--it causes the lexically enclosing method to return (in this case #make_http_request), and it worked just fine on em-http-request 0.2.7.

I did a git bisect, and it appears that this commit is the first commit where this no longer worked.

I can rewrite the method like this, and it seems to work fine:

def make_http_request(url)
  http = nil
  EventMachine.run do
    http = EventMachine::HttpRequest.new(url).get
    http.callback { EventMachine.stop }
  end 
  http
end

So I can work around it.

@igrigorik
Copy link
Owner

Right, I see. It's not obvious to me why the redirect logic would be causing this behavior. I'll take a closer look, but since the above works, we ok to close the ticket?

@myronmarston
Copy link
Author

Yep, thanks.

This issue was closed.
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

2 participants