-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Server run thread safety fix [changelog skip] #2435
Server run thread safety fix [changelog skip] #2435
Conversation
Log after `server.run` in Single mode since some integration tests use this message for timing stop signals.
@@ -1141,4 +1141,12 @@ def test_client_quick_close_no_lowlevel_error_handler_call | |||
sleep 0.5 | |||
assert_empty @events.stdout.string | |||
end | |||
|
|||
def test_run_stop_thread_safety | |||
100.times do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How long does this take to run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe 0.3 sec on JRuby, less on MRI. I should have reviewed this earlier, but...
I suspect I can revert the band-aids for JRuby (the sleep after run). This is the same issue of Server#run
getting messed up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@notify << message | ||
rescue IOError, NoMethodError, Errno::EPIPE | ||
# The server, in another thread, is shutting down | ||
@notify << message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup here.
Description
This PR fixes a race-condition creating the
@check, @notify
pipe inServer
, which caused various intermittent test failures on JRuby.The issue can be triggered by a call to
#run
(which calls#handle_servers
in a background-thread) followed immediately by#stop
(which calls#notify_safely
). This can result in two separate@check, @notify
pipes getting created concurrently, causing the signal sent by#stop
to not get picked up by the listen-loop in#handle_servers
, and therefore fail to exit as expected. This PR adds a testtest_run_stop_thread_safety
demonstrating the race condition that consistently fails on JRuby without this fix (see this test run).The fix moves pipe-creation into
Server#run
(before the background thread is spawned), making the behavior more consistent that the server will stop as long as the call to#stop
comes after the call to#run
returns.This PR includes a related timing change in
Single
, moving theUse Ctrl-C to stop
log message after the call toServer#run
. This is because thewait_for_server_to_boot
integration-test helper uses this log message to determine when the server is 'booted', and some integration tests (e.g.,test_int_refuse
) send anINT
signal (which callsstop
) immediately after this log message is printed, causing intermittent failures if thestop
call arrived before therun
call finished. The change ensures thatstop
always occurs afterrun
, avoiding intermittent failures in this test.Your checklist for this pull request
[changelog skip]
or[ci skip]
to the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.