-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Net::HTTP::Persistent::Error: too many connection resets (due to Connection reset by peer - Errno::ECONNRESET) after 2 requests on 14759220 #123
Comments
I am getting the same error when attempting an http POST, but it only occurs intermittently. |
Same here. |
I encountered this too after upgrading from 1.0.0, along with this one in a few other places:
Easily resolved by sticking with 1.0.0, which seems much more stable compared to 2.x at the moment. |
I'll try to find out when the regression came up. |
Net::Http::Persistent introduced in 4d074f4 Some stuff from debug log:
I also checked headers in Firefox plugin: Tamper Data |
Any solution to this issue? I am getting similar error with no effect increasing keep_alive_time or open_time: |
Same here, seems to fluctuate between EOF and ECONNRESET |
Confirmed with Mechanize 2.0.1. Please fix this issue. |
+1 I'm seeing the same thing |
Same here. It occurs regardless of https or http. If you know re-posting is harmless (as in a login form) you can temporarily set: agent.agent.http.retry_change_request = true To force a re-post, and seems it works for me. |
Another ugly workaround is to manually reset the connection before posting. #...
agent.agent.http.tap { |http|
http.reset http.connection_for(login_page.uri + form.action)
}
form.submit |
I'm also seeing this quite frequently on 2.0.1, going to look into downgrading to 1.0.0 as a short-term solution to the problem. |
Here is what looks to be going on: I see this error when I run a request, then after a brief pause, run another request, using SSL. It does not happen when I run the requests back to back. I got a full backtrace from line 460 of persistent.rb, and that showed that the IOError was being raised from buffering.rb:145 in read_nonblock at a call to sysread_nonblock, called from net/protocol.rb:135 in rbuf_fill. Digging down, it looks like sysread_nonblock is implemented (in 1.9.2) in the core file ossl_ssl.c, and only returns an IOError if one of two errors occurred, SSL_ERROR_ZERO_RETURN or SSL_ERROR_SYSCALL. The documentation here: http://www.openssl.org/docs/ssl/SSL_get_error.html The problem is going to be figuring out when that is the case so you can retry safely for non-idempotent queries. knu's workaround will work if you know it is safe to do so. You can't just always retry on EOFError because other levels can throw EOFError for different reasons. |
I'm getting a similar error using 2.0.1. It happens on a POST request in which the server takes about 2-3 min to respond. The error I get is a little different though: "too many connection resets (due to Resource temporarily unavailable - Timeout::Error)" Fixed it temporarily by reverting back to 1.0.0 and setting high agent.read_timeout and agent.open_timeout settings. |
we are facing similar problem though. i think we will choose the downgrade path and test out 2.0.2 again when its released. |
anybody also getting occasional SocketError's about getaddrinfo failing because it couldnt find the remote host in addition to the ECONNRESET errors because of this bug? or is this a different problem that i'm having? |
Having same problem :( |
any updates? |
Hey any updates... same here... |
I started using selenium web driver. |
same here... this issue is 4 months old now. can we await any updates? |
I don't know what happened, but it is working for me now... things i have done: |
The issue is related to:
Without example scripts to illustrate and reproduce your specific problem it is difficult to find a "fix" for your specific program. |
Here is one example of a server I've come across that triggers this behavior:
It works without the sleep, which makes me think it has something to do with the keep alive behavior of the server. |
I get the same error with @jinschoi's script. And here's a similar trace from httpclient. Relevant part is 'KeepAliveDisconnected'. HTTPClient tries to re-post under some condition since we might not be able to detect a socket disconnection by peer. EDIT: I forgot to add this URL: https://gist.github.com/1280318 |
I've released net-http-persistent 2.2 which will reset connections that have been idle for 5 seconds. Can some of you try your scripts with master @1fd7c77 or newer? |
From my investigation at that time, the server for 'https://junecloud.com/sync/deliveries/' seems to have 1 or 2 sec as KeepAliveTimeout. I'm writing this because I just thought that the second access in 1~4 sec might raise an error as same as before. |
This has been failing for me with a mixture of "too many connection resets" and plain timeouts pretty consistently for the last few months. Attempts to set idle_timeout, keep_alive and retry_change_requests doesn't help. client = Mechanize.new
page = client.get 'http://www.us.hsbc.com' Meanwhile (in the same irb window) this will generally work fine: html = open('http://www.us.hsbc.com') { |f| f.read } |
This bug still exists. It's the biggest problem with mechanize. I really wish it could be resolved. Here is another example: agent = Mechanize.new
agent.get('https://site.com/whatever')
#=> Net::HTTP::Persistent::Error: too many connection resets (due to Connection reset by peer - SSL_connect - Errno::ECONNRESET) after 0 requests on 70362676419080, last used 1379112036.219295 seconds ago
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
#=> 0
agent.get('https://site.com/whatever')
#=> Net::HTTP::Persistent::Error: too many connection resets (due to Connection reset by peer - SSL_connect - Errno::ECONNRESET) after 0 requests on 70362676321280, last used 1379112135.65024 seconds ago\ Here is the agent:
I'm able to Curl the https url just fine and get the HTML response. It's clearly something in the ruby code that's to blame. |
Disabling the To diagnose this problem you'll need to show the URL you are connecting to. https://site.com does not exist:
PS: Use code fences:
|
https://isapps.acxiom.com/optout/optout.aspx On Fri, Sep 13, 2013 at 3:53 PM, Eric Hodel notifications@github.comwrote:
|
@bsgreenb your problem is not the problem described in this issue, but is a server negotiation problem as I can't connect using SSLSocket defaults:
Setting the
Here's the certificate chain which should help you track down the right certificate if you are also missing it:
This was from I strongly recommend you DO NOT SET |
Thanks. What are the steps involved in adding a certificate that mechanize can On Fri, Sep 13, 2013 at 4:25 PM, Eric Hodel notifications@github.comwrote:
|
You should be able to retrieve the CA cert from your browser (export it in PEM format) and add it to a OpenSSL::X509::Store then set Mechanize#cert_store= |
So when I access the url it's a chain of certificates that goes: Which one should I export? On Fri, Sep 13, 2013 at 5:08 PM, Eric Hodel notifications@github.comwrote:
|
Try both Entrust.net certificates, but you may be able to get away with the "(2048)" one alone. You'll need to add each separately to the Store. |
Hmm, thanks for the reference to ssl_version. Setting that to :TLSv1 fixes access to us.hsbc.com also. It seems kind of odd that open-uri works fine - I guess some difference in the defaults? |
Eric, I manually set the cert_store to the exported .pem file and I still get the Here's what I did: And I get:Net::HTTP::Persistent::Error: too many connection resets (due to On Fri, Sep 13, 2013 at 11:17 PM, aquasync notifications@github.com wrote:
|
curl --cacert test.pem -v $ curl --cacert test.pem -v https://isapps.acxiom.com/optout/optout.aspx
< HTTP/1.1 200 OK On Mon, Sep 16, 2013 at 12:11 PM, Ben Greenberg bsgreenb@gmail.com wrote:
|
Think I've finally resolved the issues I was running into with these errors. It comes down to this characteristic: "Mechanize defaults to validating SSL certificates using the default CA certificates for your platform." Mechanize might be fine at request SSL sites from one machine and failing from another for this reason. That's why I recommend everyone specify a cert file that's in version control and can be used across environments. Also, to the maintainers of Mechanize,
|
Mechanize uses the default CA path, see: https://github.com/drbrain/net-http-persistent/blob/master/lib/net/http/persistent.rb#L1171 If you don't have the necessary root certificates in your default CA path there's not much we can do about that. Clearer errors need to happen in openssl and net/http over in https://bugs.ruby-lang.org I'll see what I can do for better documentation for the "too many connection resets" problems. |
Also wanted to add that I had to set agent.ssl_version = :TLSv1 for it to On Mon, Sep 23, 2013 at 9:53 PM, Eric Hodel notifications@github.comwrote:
|
Certs, CA paths, ssl_version, keep_alive, idle_timeout, retry_change_requests, etc...none of the suggestions above have had any effect at eliminating this bug from intermittently occurring in our high-volume production scrapers based on Mechanize. As an experiment, I created a monkey-patch that simply shuts down the underlying persistent connection and tries again with a new one, whenever this error is caught. I've now been using this in production for high-volume scrapers for a few months. It has 100% eliminated this problem with no observable negative side-effects. YMMV. Here's my post about this workaround, along with the code: http://scottwb.com/blog/2013/11/09/defeating-the-infamous-mechanize-too-many-connection-resets-bug/ |
@scottwb what is your request mix? The HTTP spec only allows a retry of GET, HEAD and other idempotent methods. POST, PUT and other methods that modify data cannot be retried by a library like net-http-persistent, but can if you have application-specific knowledge. That's up to you to add to your library, I'm not comfortable adding such a thing to net-http-persistent because it may lead to a double-POST (which is bad) in untrained hands. |
I'm going to close this for now. I think it's hard to come up with a literal fix that satisfies everything in this issue. Happy to discuss any problems in fresh issues. |
I get this error:
Еhis happens in a long process. The number of requests and url of error may vary.
I tried different settings, including headers, but the error could not be fixed.
any ideas? Thank you |
I am trying to do some simple screen scraping on etrade's website but am getting a similar issue that was reported by someone earlier. I read through that message thread but it doesn't look like it was ever resolved.
Here is the error I am getting back:
Here is my code:
Any ideas?
Thanks
The text was updated successfully, but these errors were encountered: