From: Aaron Patterson Date: 2008-02-05T07:07:28+09:00 Subject: [PATCH] net/http EOF error Hi, I've encountered an error in net/http where if the server closes the connection, net/http will get an EOF error. Here is a short example to reproduce the error: require 'net/http' request = Net::HTTP::Get.new('http://google.com/') request.add_field('Connection', 'keep-alive') http_obj = Net::HTTP.new('google.com', 80) http_obj.start 2.times { http_obj.request(request) { |response| response.read_body } sleep 10 # Comment me out for no error! } I've opened a ticket on rubyforge: http://rubyforge.org/tracker/index.php?func=detail&aid=17778&group_id=426&atid=1700 Here is a patch (against 1.8) that fixes the error: Index: lib/net/http.rb =================================================================== --- lib/net/http.rb (revision 15376) +++ lib/net/http.rb (working copy) @@ -1060,7 +1060,7 @@ private def begin_transport(req) - if @socket.closed? + if @socket.closed? || @socket.eof? connect end if @seems_1_0_server Index: lib/net/protocol.rb =================================================================== --- lib/net/protocol.rb (revision 15376) +++ lib/net/protocol.rb (working copy) @@ -62,6 +62,10 @@ "#<#{self.class} io=#{@io}>" end + def eof? + @io.eof? + end + def closed? @io.closed? end -- Aaron Patterson http://tenderlovemaking.com/