Breaks net/http/persistent for allowed requests with Connection: close response header #208

gtd opened this Issue Aug 25, 2012 · 1 comment


None yet

2 participants

gtd commented Aug 25, 2012

I was bit by a variant of the issue Mislav mentioned in #188. It was significant work to tease apart because I'm using Mechanize and VCR and I'm not really familiar with the internals of any of the parts. However I was able to reduce this to a minimal test case:

require 'net/http/persistent'
require 'webmock'

uri = URI '' # Arbitrary URI with Connection: close response header
http = 'test'


http.request uri

The error is:

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 70295747128800, last used 
1345910926.7613492 seconds ago (Net::HTTP::Persistent::Error)
    from gems/net-http-persistent-2.7/lib/net/http/persistent.rb:848:in `request'

The actual trigger of this error is the if connection_close?(req) condition in net/http/persistent.rb (line 812 in v2.7). This causes the connection to be closed, which for some reason (I haven't analyzed this yet, but I'm guessing it should be obvious to you) causes WebMock to refire the request. And when it refires it blows up.

This is fixed by the workaround described in the README of setting :net_http_connect_on_start to true, however that makes me worried about leaking connections when I don't want them. Ultimately I think the whole structure of NetHttpAdapter should be reconsidered with the semantics of net/http/persistent where connections are closed optionally right in the request method.

@rweng rweng referenced this issue in saucelabs/sauce_ruby Jul 3, 2013

conflict with webmock #150

bblimke commented Jul 5, 2013

Fixed with WebMock 1.13.0

@bblimke bblimke closed this Jul 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment