Skip to content

Report the parent's fd numbers from forkserver pool workers - #483

Open
tzifudzi wants to merge 1 commit into
celery:mainfrom
tzifudzi:forkserver-preserve-worker-fds
Open

tzifudzi wants to merge 1 commit into
celery:mainfrom
tzifudzi:forkserver-preserve-worker-fds

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

Celery doesn't offer forkserver yet, even though billiard supports it. It can't be enabled safely today, because the parent loses track of which workers are free.

A worker identifies itself to the parent by the fd numbers of its pipes. Under fork and spawn those match the parent's numbers, but under forkserver the pipes arrive over a socket and can get different numbers in the child. The parent then can't match the message to a worker, so Celery leaves that worker marked busy and stops sending it tasks.

Fix

Worker.__reduce__ now sends the parent's inqW_fd and synqW_fd along with the worker, so the child reports those instead of its own, which allows the parent to more reliably identify the worker and mark it free when its task finishes.

Related PRs

Restart the fork server if it dies celery/billiard #484
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

A pool worker tells the parent which worker it is by sending inqW_fd in
READY and synqW_fd in ACK. Celery keys its worker lookups and its busy
set by those numbers, and with synack it writes the ack to the reported
synqW_fd, so they have to be the parent's numbers.

The child worked them out from its own fd table. Under fork and POSIX
spawn that gives the parent's numbers, but a forkserver child receives
its pipes over a socket and can see them under different numbers. The
parent then cannot find the worker that sent the message, so Celery
leaves it marked busy and stops sending it tasks.

Send the parent's numbers along with the worker in Worker.__reduce__, so
the child reports those instead. The child only uses them as labels,
never to read or write a pipe. The message format and Worker.__init__
are unchanged, and fork and spawn report the same values as before.

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 09:23
@tzifudzi tzifudzi closed this Nov 29, 2026
@tzifudzi tzifudzi reopened this Nov 29, 2026
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.

1 participant