Backport #2758

NoMethodError instead of Errno::ECONNREFUSED when Net::HTTP cannot connect

Added by thatothermitch (Mitch Williams) over 2 years ago. Updated about 1 year ago.

[ruby-core:28231]
Status:Closed Start date:02/19/2010
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-

Description

The code:

require net/http.rb
n = Net::HTTP.new('server-that-is-not-listening-on-port-eighty')
n.request_head('/')

Used to throw: "Errno::ECONNREFUSED: Connection refused - connect(2)"

But after http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25851 the code throws: "NoMethodError: undefined method `closed?' for nil:NilClass"

From line 1060 of net/http.rb.  It looks like the code was intended to close sockets in the event of an error, but it assumes the socket actually exists.

Related issues

duplicates Backport87 - Backport #2708: NoMethodError exception generated when using net/http Closed 02/03/2010
duplicated by Backport87 - Backport #2779: Net::HTTP#get raises NoMethodError Closed 02/22/2010

History

Updated by shyouhei (Shyouhei Urabe) about 2 years ago

  • Status changed from Open to Closed
This issue was solved with changeset r27955.
John, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF