Skip to content

Commit 554b884

Browse files
authored
Merge pull request #21 from rhenium/ky/keep-alive-finished-connection
Reset keep_alive timer on new connection
2 parents b81bd79 + 0a013de commit 554b884

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/net/http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ def connect
10471047
write_timeout: @write_timeout,
10481048
continue_timeout: @continue_timeout,
10491049
debug_output: @debug_output)
1050+
@last_communicated = nil
10501051
on_connect
10511052
rescue => exception
10521053
if s

test/net/http/test_http.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,30 @@ def test_keep_alive_get_auto_retry
11681168
}
11691169
end
11701170

1171+
def test_keep_alive_reset_on_new_connection
1172+
# Using WEBrick's debug log output on accepting connection:
1173+
#
1174+
# "[2021-04-29 20:36:46] DEBUG accept: 127.0.0.1:50674\n"
1175+
@log_tester = nil
1176+
@server.logger.level = WEBrick::BasicLog::DEBUG
1177+
1178+
start {|http|
1179+
res = http.get('/')
1180+
http.keep_alive_timeout = 1
1181+
assert_kind_of Net::HTTPResponse, res
1182+
assert_kind_of String, res.body
1183+
http.finish
1184+
assert_equal 1, @log.grep(/accept/i).size
1185+
1186+
sleep 1.5
1187+
http.start
1188+
res = http.get('/')
1189+
assert_kind_of Net::HTTPResponse, res
1190+
assert_kind_of String, res.body
1191+
assert_equal 2, @log.grep(/accept/i).size
1192+
}
1193+
end
1194+
11711195
class MockSocket
11721196
attr_reader :count
11731197
def initialize(success_after: nil)

0 commit comments

Comments
 (0)