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

Minor timeout bug in Reactor #2282

Closed
wjordan opened this issue May 21, 2020 · 2 comments
Closed

Minor timeout bug in Reactor #2282

wjordan opened this issue May 21, 2020 · 2 comments

Comments

@wjordan
Copy link
Contributor

wjordan commented May 21, 2020

There is a minor timeout bug in Reactor affecting unit-test stability, real-world impact is probably minimal.

To Reproduce

  • Reduce first_data_timeout from 2 to 0.01 in test_timeout_in_data_phase (just to reproduce the issue quicker- the bug can still affect the existing test):
    @server.first_data_timeout = 2
  • Run the test repeatedly in a while loop and it will eventually hang:
    while :; do ruby -Ilib:test test/test_puma_server.rb --name /test_timeout_in_data_phase/; done

Analysis

In Reactor, the monitor of the Client object (c) is removed from @timeouts when the object becomes readable (has new data available to read):

puma/lib/puma/reactor.rb

Lines 214 to 221 in 19b2a21

# We have to be sure to remove it from the timeout
# list or we'll accidentally close the socket when
# it's in use!
if c.timeout_at
@mutex.synchronize do
@timeouts.delete mon
end
end

However, the object is only actually moved from the reactor to the thread-pool when c.try_to_finish is true (when the header / body is fully buffered):

puma/lib/puma/reactor.rb

Lines 224 to 227 in 19b2a21

if c.try_to_finish
@app_pool << c
clear_monitor mon
end

This leaves the edge-case where an object becomes readable but try_to_finish returns false, leaving the object in the reactor in a state where it will never time out.

@wjordan wjordan mentioned this issue May 21, 2020
8 tasks
@nateberkopec nateberkopec added bug maintenance waiting-for-review Waiting on review from anyone and removed waiting-for-review Waiting on review from anyone labels May 22, 2020
@wjordan
Copy link
Contributor Author

wjordan commented Oct 7, 2020

Fixed by #2279.

@wjordan wjordan closed this as completed Oct 7, 2020
@dentarg
Copy link
Member

dentarg commented Jan 17, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants