Skip to content


Subversion checkout URL

You can clone with
Download ZIP


no support for net-http-persistent #188

rkh opened this Issue · 21 comments

5 participants

rkh commented

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


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 = 'Faraday'

request = '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

@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.


It should be fixed with WebMock 1.13.0

@bblimke bblimke closed this

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


@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?


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:

       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
VCR.use_cassette 'acassete' do
  mechanize =
  mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  mechanize.agent.http.ssl_version = :TLSv1

  mechanize.get('...https uri...')

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


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


Edited the code to include the vc config with webmock hook


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?


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


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

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'

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


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!


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

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'

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


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:


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)


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.