Do not accept new requests on shutdown #1685
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.
Related to #1186
Problem:
When puma process receives
TERM
signal it tries to finish all current requests and terminate. But... it also accepts "new requests" and these requests are hanged. When the processing of all current requests (which was made before shutdown signal is received) are finished, all "new requests" are closed with errorConnection reset by peer
.This error prevents load balancers (like nginx) to forward these requests to other web-server, because this error does not guarantee that the request was not processed, but this guarantee is required to forward not idempotent HTTP request (like POST).
Seems like puma should refuse new requests by closing a socket that accepts new connections.
Read #1186 (comment) for implementation details.
This solution is simple and fast. But probably there is a better solution.