Repository navigation
Conversation
The fork server is started once and never checked again. If it dies, every later attempt to start a process fails with ConnectionRefusedError, because nothing listens on its socket any more, so a pool can no longer replace its workers. Before asking for a new process, check whether the fork server has exited, as CPython does (python/cpython#75489). If it has, forget it and start a new one. If that start fails, the next call tries again. Only the process that started the fork server can check on it. A process the server started, or a forked copy of the one that started it, keeps using it without checking, as billiard does today. CPython instead starts a second fork server in the first case and raises ChildProcessError in the second. A pool worker that failed to start stayed in the pool, and cleaning it up at the next maintenance raised KeyError because it was never registered under a pid. Clean it up without raising, so the pool goes on to start a replacement. Part of celery/celery#11096
Route new workers to a fresh fork server before recycling the pool so they inherit the current preloaded code. Let the retired server exit on its own: stopping it early can kill workers on Linux through their parent-death signal. Serialize the switch with worker startup and reap the retired server after its last client exits. Part of celery/celery#11096
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Pool.restart()recycles workers, but underforkservertheir replacements inherit any preloaded modules from the same server. Those modules still contain the code loaded when the server started.Fix
Start a fresh fork server before signaling the existing workers to exit. Route new worker requests to the new server.
Related PRs
Report the parent's fd numbers from forkserver pool workers celery/billiard #483
Restart the fork server if it dies celery/billiard #484
Support forkserver as a prefork start method celery/celery #11177
Support preloading modules in the fork server celery/celery #11178