drbrain / net-http-persistent

Thread-safe persistent connections with Net::HTTP
http://seattlerb.rubyforge.org/net-http-persistent
339 stars 117 forks source link

net-http-persistent incompatible with vcr/fakeweb when reuse_ssl_sessions==true #13

Closed mattbrictson closed 12 years ago

mattbrictson commented 12 years ago

By default, net-http-persistent has the option reuse_ssl_sessions = true, which causes Net::HTTP::Persistent::SSLReuse to be used as the underlying http class, rather than Net::HTTP. SSLReuse redefines connect to use the socket layer directly. The first line is:

s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }

This apparently breaks higher level http mocking libraries. For example, when using the vcr gem with fakeweb mocking, I expect vcr to replay a previously recorded http interaction. Instead, I get an error like this:

Net::HTTP::Persistent::Error:
connection refused

Currently, my workaround is to prevent net-http-persistent from using the SSLReuse class during tests.

http = Net::HTTP::Persistent.new
# Disable SSL pool in test environment, as it breaks fakeweb
http.reuse_ssl_sessions = false if Rails.env.test?

Perhaps this there is no other way around this, but I thought I should at least document the problem here, as a Google search did not turn up any other explanations.

zzak commented 12 years ago

Another me too, adding work around for mechanize

agent = Mechanize.new
agent.agent.http.reuse_ssl_sessions = false
drbrain commented 12 years ago

I'll need to add code to detect if fakeweb is active to disable SSL session reuse automatically, but it'll have to wait until after the mechanize bugfix release.

drbrain commented 12 years ago

Fixed by #14