Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timing out requests too early #2606

Merged
merged 2 commits into from Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
28 changes: 27 additions & 1 deletion test/test_puma_server.rb
Expand Up @@ -383,11 +383,13 @@ def test_status_hook_fires_when_server_changes_states
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
Expand All @@ -398,6 +400,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