Skip to content

Commit

Permalink
Merge pull request #21 from rhenium/ky/keep-alive-finished-connection
Browse files Browse the repository at this point in the history
Reset keep_alive timer on new connection
  • Loading branch information
hsbt authored Nov 4, 2021
2 parents b81bd79 + 0a013de commit 554b884
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ def connect
write_timeout: @write_timeout,
continue_timeout: @continue_timeout,
debug_output: @debug_output)
@last_communicated = nil
on_connect
rescue => exception
if s
Expand Down
24 changes: 24 additions & 0 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,30 @@ def test_keep_alive_get_auto_retry
}
end

def test_keep_alive_reset_on_new_connection
# Using WEBrick's debug log output on accepting connection:
#
# "[2021-04-29 20:36:46] DEBUG accept: 127.0.0.1:50674\n"
@log_tester = nil
@server.logger.level = WEBrick::BasicLog::DEBUG

start {|http|
res = http.get('/')
http.keep_alive_timeout = 1
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
http.finish
assert_equal 1, @log.grep(/accept/i).size

sleep 1.5
http.start
res = http.get('/')
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
assert_equal 2, @log.grep(/accept/i).size
}
end

class MockSocket
attr_reader :count
def initialize(success_after: nil)
Expand Down

0 comments on commit 554b884

Please sign in to comment.