Skip to content

Restart the fork server if it dies - #484

Open
tzifudzi wants to merge 1 commit into
celery:mainfrom
tzifudzi:forkserver-restart-dead-server
Open

tzifudzi wants to merge 1 commit into
celery:mainfrom
tzifudzi:forkserver-restart-dead-server

Conversation

@tzifudzi

@tzifudzi tzifudzi commented Nov 28, 2026 •

Copy link
Copy Markdown

Part of enhancement Support forkserver as a worker_pool_start_method celery/celery#11096.

Problem

billiard starts the fork server once and never checks on it again. If the fork server dies, every later attempt to create a worker fails with ConnectionRefusedError, because nothing is listening on its socket any more. The pool can then no longer replace workers that exit.

Fix

ForkServer.ensure_running now checks whether the fork server has exited before asking it for a new process, the way CPython does (python/cpython#75489). If it has, billiard forgets it and starts a new one. If that start fails, the next call tries again.

Related PRs

Report the parent's fd numbers from forkserver pool workers celery/billiard #483
Replace the fork server on pool restart celery/billiard #485
Support forkserver as a prefork start method celery/celery #11177
Support preloading modules in the fork server celery/celery #11178

@tzifudzi
tzifudzi force-pushed the forkserver-restart-dead-server branch 4 times, most recently from e0c424d to 2084796 Compare November 28, 2026 21:13
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
@tzifudzi

Copy link
Copy Markdown
Author

@auvipy regarding enhancement celery/celery#11096, ready with PRs now, please review. Separated PRs into separate granular changes to make them easier to review.

@auvipy
auvipy self-requested a review November 29, 2026 02:16
@auvipy

auvipy commented Nov 29, 2026

Copy link
Copy Markdown
Member

OK

@auvipy

auvipy commented Nov 29, 2026

Copy link
Copy Markdown
Member

please dont force push, I am not sure why the Unit test builds are not triggered though

@auvipy auvipy closed this Nov 29, 2026
@auvipy auvipy reopened this Nov 29, 2026
@tzifudzi

Copy link
Copy Markdown
Author

Got it won't force push on future PR edits, seems unit tests are triggered now, they need a maintainer to trigger workflows it seems

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants