Skip to content

Commit

Permalink
Use the original backtrace for errors in #reset
Browse files Browse the repository at this point in the history
This will help debugging IOErrors that occur when resetting a
connection.

Fixes #41
  • Loading branch information
drbrain committed Jan 22, 2014
1 parent 14335ad commit 590be77
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions History.txt
Expand Up @@ -4,6 +4,8 @@
* Added license to gemspec. Issue #47 by Benjamin Fleischer
* Set Net::HTTP#keep_alive_timeout when supported by ruby. Pull request #53
by Dylan Thacker-Smith.
* The backtrace is preserved for errors in #reset to help with debugging.
Issue #41 by Andrew Cholakian.

=== 2.9 / 2013-07-24

Expand Down
8 changes: 6 additions & 2 deletions lib/net/http/persistent.rb
Expand Up @@ -956,9 +956,13 @@ def reset connection

start connection
rescue Errno::ECONNREFUSED
raise Error, "connection refused: #{connection.address}:#{connection.port}"
e = Error.new "connection refused: #{connection.address}:#{connection.port}"
e.set_backtrace $@
raise e
rescue Errno::EHOSTDOWN
raise Error, "host down: #{connection.address}:#{connection.port}"
e = Error.new "host down: #{connection.address}:#{connection.port}"
e.set_backtrace $@
raise e
end

##
Expand Down
2 changes: 2 additions & 0 deletions test/test_net_http_persistent.rb
Expand Up @@ -1339,6 +1339,7 @@ def c.start; raise Errno::EHOSTDOWN end
end

assert_match %r%host down%, e.message
assert_match __FILE__, e.backtrace.first
end

def test_reset_io_error
Expand All @@ -1363,6 +1364,7 @@ def c.start; raise Errno::ECONNREFUSED end
end

assert_match %r%connection refused%, e.message
assert_match __FILE__, e.backtrace.first
end

def test_retry_change_requests_equals
Expand Down

0 comments on commit 590be77

Please sign in to comment.