drbrain / net-http-persistent

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

Strange EOFError on ruby-2.0.0-preview1 #34

Closed postmodern closed 11 years ago

postmodern commented 12 years ago

While running the specs for gscraper I got the following error repeatedly under Ruby 2.0.0-preview1:

  29) GScraper::Search::AJAXQuery queries from AJAX search URLs should have a query
     Net::HTTP::Persistent::Error:
       too many connection resets (due to Content-Length (1506) does not match response body length (5306) - EOFError) after 0 requests on 69848766768600, last used 1351826201.368255 seconds ago
lbguilherme commented 11 years ago

I have the same issue while trying to get some url with mechanize. Mechanize 2.5.1 Net-Http-Persistent 2.8 Ruby 2.0.0-dev (today's tree)

drbrain commented 11 years ago

Do you have a simple, easy to reproduce example?

postmodern commented 11 years ago

Using mechanize 2.5.1 and net-http-persistent 2.8 on ruby 2.0.0-rc2:

require 'mechanize'

agent = Mechanize.new
p agent.get('http://example.com/')

/home/hal/.gem/ruby/2.0.0/gems/net-http-persistent-2.8/lib/net/http/persistent.rb:959:in `rescue in request': too many connection resets (due to Content-Length (606) does not match response body length (1111) - EOFError) after 0 requests on 70321166174580, last used 1360376030.637872 seconds ago (Net::HTTP::Persistent::Error)
from /home/hal/.gem/ruby/2.0.0/gems/net-http-persistent-2.8/lib/net/http/persistent.rb:968:in `request'
from /home/hal/.gem/ruby/2.0.0/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:258:in `fetch'
from /home/hal/.gem/ruby/2.0.0/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:949:in `response_redirect'
from /home/hal/.gem/ruby/2.0.0/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:299:in `fetch'
from /home/hal/.gem/ruby/2.0.0/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:949:in `response_redirect'
from /home/hal/.gem/ruby/2.0.0/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:299:in `fetch'
from /home/hal/.gem/ruby/2.0.0/gems/mechanize-2.5.1/lib/mechanize.rb:407:in `get'
from mechanize_test.rb:6:in `block in <main>'
from mechanize_test.rb:5:in `times'
from mechanize_test.rb:5:in `<main>'
postmodern commented 11 years ago

Actually the 100.times isn't even necessary, fails on the first call.

drbrain commented 11 years ago

This error is due to Ruby 2 handling content-encoding automatically under the covers, but not informing the user. The bug is actually in mechanize, but I'll leave this open.

drbrain commented 11 years ago

Filed https://bugs.ruby-lang.org/issues/7831 with a patch, closing this.

postmodern commented 11 years ago

Thank you!