Skip to content

Commit

Permalink
Fix timing out when we get a slow request
Browse files Browse the repository at this point in the history
Fixes puma#2574 (regression in v5.0.3).

Co-authored-by: Daniel Huckstep <daniel@huckstep.ca>
Co-authored-by: Will Jordan <will@code.org>
  • Loading branch information
wjordan and darkhelmet committed Apr 20, 2021
1 parent 7ca15c1 commit 7e11ad1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/puma/server.rb
Expand Up @@ -295,6 +295,9 @@ def reactor_wakeup(client)
@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)
Expand Down
24 changes: 24 additions & 0 deletions test/test_puma_server.rb
Expand Up @@ -398,6 +398,30 @@ def test_timeout_data_no_queue
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"]] }

Expand Down

0 comments on commit 7e11ad1

Please sign in to comment.