mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Fix timing out requests too early (#2606)
* Fix timing out when we get a slow request Fixes #2574 (regression in v5.0.3). Co-authored-by: Daniel Huckstep <daniel@huckstep.ca> Co-authored-by: Will Jordan <will@code.org> * Update test_timeout_in_data_phase Complete request to ensure short timeout is used properly. Co-authored-by: Daniel Huckstep <daniel@huckstep.ca>
This commit is contained in:
parent
366496b89d
commit
a717b27354
2 changed files with 30 additions and 1 deletions
|
@ -295,6 +295,9 @@ module Puma
|
|||
@thread_pool << client
|
||||
elsif shutdown || client.timeout == 0
|
||||
client.timeout!
|
||||
else
|
||||
client.set_timeout(@first_data_timeout)
|
||||
false
|
||||
end
|
||||
rescue StandardError => e
|
||||
client_error(e, client)
|
||||
|
|
|
@ -383,11 +383,13 @@ EOF
|
|||
end
|
||||
|
||||
def test_timeout_in_data_phase
|
||||
@server.first_data_timeout = 2
|
||||
@server.first_data_timeout = 1
|
||||
server_run
|
||||
|
||||
sock = send_http "POST / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nContent-Length: 5\r\n\r\n"
|
||||
|
||||
sock << "Hello" unless IO.select([sock], nil, nil, 1.15)
|
||||
|
||||
data = sock.gets
|
||||
|
||||
assert_equal "HTTP/1.1 408 Request Timeout\r\n", data
|
||||
|
@ -398,6 +400,30 @@ EOF
|
|||
test_timeout_in_data_phase
|
||||
end
|
||||
|
||||
# https://github.com/puma/puma/issues/2574
|
||||
def test_no_timeout_after_data_received
|
||||
@server.first_data_timeout = 1
|
||||
server_run
|
||||
|
||||
sock = send_http "POST / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nContent-Length: 11\r\n\r\n"
|
||||
sleep 0.5
|
||||
|
||||
sock << "hello"
|
||||
sleep 0.5
|
||||
sock << "world"
|
||||
sleep 0.5
|
||||
sock << "!"
|
||||
|
||||
data = sock.gets
|
||||
|
||||
assert_equal "HTTP/1.1 200 OK\r\n", data
|
||||
end
|
||||
|
||||
def test_no_timeout_after_data_received_no_queue
|
||||
@server = Puma::Server.new @app, @events, queue_requests: false
|
||||
test_no_timeout_after_data_received
|
||||
end
|
||||
|
||||
def test_http_11_keep_alive_with_body
|
||||
server_run app: ->(env) { [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue