Fix hang on shutdown in test_refork [changelog skip] #2442
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a hang on shutdown that occurred intermittently in
test_refork
(example). I reproduced the hang more consistently runningtest_refork
with an extrasleep
after the'b'
(boot) message and before it starts the server (e.g., line 106 below):puma/lib/puma/cluster/worker.rb
Lines 99 to 108 in aae4d4d
The PR contains two small fixes.
TERM
signal (0018edd). This handles some (but not 100% of all) edge cases where theTERM
signal is received and callsserver.stop
before the server has started.fork_worker
is used, the call toProcess.wait
inwait_workers
returnsECHILD
for forked workers. This commit adds a call tow.term
in the rescue clause, matching the behavior whenfork_worker
is not used and ensuring workers shut down properly. This should handle all other edge-cases where a worker receivesTERM
before the server starts.Finally, note that this bug started occurring more frequently after #2435, because that PR changed behavior so that calling
#stop
before#run
now has no effect. I've addedtest_command_ignored_before_run
to clarify this new behavior in a unit test. I think this is more intuitive and predictable behavior overall, but we can change it back if anyone disagrees or if the change continues to cause any other issues.