Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

no support for net-http-persistent #188

Closed
rkh opened this Issue · 21 comments

5 participants

@rkh
rkh commented

would be cool if mocking net-http-persistent would be possible

@mislav

Just got bitten by the fact that Webmock can break net-http-persistent even for requests that it allows.

I've got a mysterious failure with net-http-persistent getting a 204 from a local test server which only got alleviated when I stopped including Webmock in the test suite. The thing is, Webmock was supposed to allow local requests:

require 'net/https'
require 'net/http/persistent'

# <culprit>
require 'webmock'
WebMock.disable_net_connect! :allow_localhost => true
# </culprit>

require 'uri'
uri = URI('http://127.0.0.1:4567/204')

http = Net::HTTP::Persistent.new 'Faraday'

request = Net::HTTPGenericRequest.new 'GET', false, true, uri.request_uri,
  'X-Faraday-Adapter' => 'net_http_persistent'

res = http.request uri, request
p res

The error was:

.../gems/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:839:in `rescue in request':
too many connection resets (due to HTTP session not yet started - IOError)
after 0 requests on 70325827178380, last used 1344776216.702357 seconds ago
(Net::HTTP::Persistent::Error)
@gtd

@mislav that just got me as well with a combination of Mechanize, VCR w/ Webmock. Quite puzzling, at least you narrowed it down for me. I think it probably deserves its own issue as well.

@bblimke
Owner

It should be fixed with WebMock 1.13.0

@bblimke bblimke closed this
@oliverbarnes

@bblimke sorry to open this again, but just got bit using 1.13. Using with vcr + mechanize

@bblimke
Owner

@oliverbarnes In 1.13, I fixed the previous problem. Now I have no idea what can it be.
Can you please give more info? It's quite difficult to investigate otherwise.
Can you reproduce it each time? Can you provide sample failing code? Stacktrace?

@oliverbarnes

I see, I didn't add more info since @gtd mentioned using the same stack a year back - I assumed it was the same problem. Here's the error:

Net::HTTP::Persistent::Error:
       too many connection resets (due to Connection reset by peer - SSL_connect - Errno::ECONNRESET)

The code that breaks:

VCR.configure do |c|
  c.hook_into :webmock
end
VCR.use_cassette 'acassete' do
  mechanize = Mechanize.new
  mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  mechanize.agent.http.ssl_version = :TLSv1

  mechanize.get('...https uri...')
end
@bblimke
Owner

thanks.
Does it happen each time you execute the request?
Can you provide more stacktrace?
Does it happen when you remove WebMock?

@bblimke
Owner

I tried the same code against https urls but no luck reproducing.

@oliverbarnes

Edited the code to include the vc config with webmock hook

@oliverbarnes

when I remove webmock I get a connection reset:

Errno::ECONNRESET: Connection reset by peer - SSL_connect

so could the persistence error be due to the server rejecting my connection several times?

@bblimke
Owner

Maybe. I'd need the stacktraces to investigate. I wonder how to get a test server to generate the same error.

@oliverbarnes

it's sounding more and more like it's a mechanize issue... :) thanks for the responsiveness @bblimke

@oliverbarnes
Errno::ECONNRESET: Connection reset by peer - SSL_connect
    from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:917:in `connect'
    from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:917:in `block in connect'
    from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/timeout.rb:51:in `timeout'
    from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:917:in `connect'
    from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:861:in `do_start'
    from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:856:in `start'
    from /Users/oliverbarnes/.rvm/gems/ruby-2.0.0-p0@districts-api/gems/net-http-persistent-2.9/lib/net/http/persistent.rb:691:in `start'
    from /Users/oliverbarnes/.rvm/gems/ruby-2.0.0-p0@districts-api/gems/net-http-persistent-2.9/lib/net/http/persistent.rb:631:in `connection_for'
    from /Users/oliverbarnes/.rvm/gems/ruby-2.0.0-p0@districts-api/gems/net-http-persistent-2.9/lib/net/http/persistent.rb:981:in `request'
    from /Users/oliverbarnes/.rvm/gems/ruby-2.0.0-p0@districts-api/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:257:in `fetch'
    from /Users/oliverbarnes/.rvm/gems/ruby-2.0.0-p0@districts-api/gems/mechanize-2.7.2/lib/mechanize.rb:432:in `get'
@bblimke
Owner

Can you also provide the stackrace with WebMock (webmock + net:http + mechanize source)?

@oliverbarnes

I'm not sure how to set up a test server with ssl for this, or if it's worth the time - we're debugging with a specific server we need to connect to. and which this same piece of code connects to, but from another app :)

it's got to be something on our end. but thanks again!

@oliverbarnes

working on the webmock + net::http + mechanize stacktrace, just a min

@oliverbarnes
Net::HTTP::Persistent::Error: too many connection resets (due to Connection reset by peer - SSL_connect - Errno::ECONNRESET) after 0 requests on 70254194699300, last used 1377122252.3975701 seconds ago
from /Users/oliverbarnes/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:917:in `connect'
@oliverbarnes

worked with ruby 1.9.3... does this make sense?

@oliverbarnes

just a last update, in case anyone comes across the same issue in the future. working theory is this is a local ssl cert problem. Looks like my ruby 1.9.3 install has it, my 2.0 didn't. BUT, I did try reinstalling 2.0 making sure the ssl cert was included, but no luck. Couple of resources:

http://d.hatena.ne.jp/johnyuan2000/20120805/1344145282
http://apple.stackexchange.com/questions/83885/ruby-2-0-0-install-via-rvm-errors-surrounding-openssl

@mislav

You don't have a problem with SSL certs. Your error is "Connection reset by peer - SSL_connect", meaning the connection never got established, so cert validation never took place. Even if it did, you disabled it with VERIFY_NONE (please don't do that). Read my post on SSL.

To learn how to set up a web server in testing that accepts HTTPS requests and validates certificates, you can study how we do it in Faraday.

This doesn't look like a Webmock bug. It does seem that your OpenSSL version is incompatible with Ruby 2.0. I don't know what RVM does, but in ruby-build we compile any Ruby 2.0 version with openssl v1.0.1, ignoring the outdated version that OS X ships with. You should at least trying upgrading RVM and reinstalling your Ruby 2.0 version (or installing a newer patch release)

@oliverbarnes

Thanks mislav, I'm reading up. About time I did my homework on SSL ;)

I did try the latter (upgrading rvm + reinstalling/updating ruby 2), with no luck, but will try without rvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.