Backport #2708
NoMethodError exception generated when using net/http
| Status: | Closed | Start date: | 02/03/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% |
||
| Category: | - | |||
| Target version: | - |
Description
I recently stumbled upon what appears to be a bug in lib/net/http.rb. Here is example code that illustrates the problem:
require 'net/http'
n = Net::HTTP.new('127.0.0.1', 1234) # or any other unused port
n.request_head('/')
The above code generates a NoMethodError exception, with the message "undefined method `closed?' for nil:NilClass". The expected result, and what was generated in prior versions of Ruby 1.8.7., is a thrown Errno::ECONNREFUSED exception.
It appears a recent change (r25851) to lib/net/http.rb changed some exception handling behavior and forgot to check if @socket is set. A proposed patch is attached that adds the additional check.
Related issues
Associated revisions
* lib/net/http.rb (Net::HTTP#request): close @socket only after
started. [ruby-core:28028]
merge revision(s) 26553:
* lib/net/http.rb (Net::HTTP#request): close @socket only after
started. [ruby-core:28028]
History
Updated by nobu (Nobuyoshi Nakada) over 2 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r26553. John, thank you for reporting this issue. Your contribution to Ruby is greatly appreciated. May Ruby be with you.
Updated by shyouhei (Shyouhei Urabe) about 2 years ago
- Status changed from Closed to Assigned
- Assignee set to shyouhei (Shyouhei Urabe)
Updated by shyouhei (Shyouhei Urabe) about 2 years ago
- Status changed from Assigned 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.