Skip to content
This repository

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

Closed
gtd opened this Issue August 25, 2012 · 1 comment

2 participants

Gabe da Silveira Bartosz Blimke
Gabe da Silveira
gtd commented August 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 'http://mubi.com/films/la-antena' # Arbitrary URI with Connection: close response header
http = Net::HTTP::Persistent.new 'test'

WebMock.allow_net_connect!

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.

Robin Wenglewski rweng referenced this issue in saucelabs/sauce_ruby July 03, 2013
Closed

conflict with webmock #150

Bartosz Blimke bblimke closed this July 05, 2013
Bartosz Blimke
Owner

Fixed with WebMock 1.13.0

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.