fix: open root container for non-forking worker pools (3.0.1)#7
Merged
Conversation
setup_di opened the root container only via worker_process_init, which Celery sends only from the prefork and solo pools. The gevent, eventlet, and threads pools run tasks in the main worker process and never send it, so under those pools the root container was never opened and every @Inject task raised ContainerClosedError. Connect the same open/close handlers to worker_init/worker_shutdown, which fire once in the main worker process for all pools. The existing worker_process_init/worker_process_shutdown pair is unchanged, still giving each forked process (prefork) its own open/close cycle.
Simulates the gevent/eventlet/threads path: build a fresh app and container, fire worker_init directly (never worker_process_init), and assert the root container opens and an @Inject task resolves. Fails without the fix, since only worker_process_init was connected before.
Release notes for the non-forking worker pool fix, plus the lightweight-lane planning change file recording the defect and fix.
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.
Summary
setup_diopened the root container only viaworker_process_init(closed viaworker_process_shutdown). Celery sendsworker_process_initonly from the prefork and solo pools — verified againstcelery/concurrency/prefork.pyandsolo.py.worker_process_init, so under those pools the root container was never opened, and modern-di 3.0's mandatory-open lifecycle made every@injecttask raiseContainerClosedError.task_always_eagerand opens the root container manually inconftest.py, so the signal wiring itself had zero coverage._open_container/_close_containerclosures toworker_init/worker_shutdownin addition to the existingworker_process_init/worker_process_shutdownpair (unchanged).worker_init/worker_shutdownfire once in the main worker process for all pools, covering gevent/eventlet/threads;worker_process_init/worker_process_shutdownstill fire per forked child (prefork) and in solo. The overlap is harmless —Container.open()no-ops when already open,close_sync()no-ops when nothing was cached.Patch release 3.0.1, no public API change.
Test plan
tests/test_lifespan.py::test_worker_init_opens_container_for_non_forking_pools) firesworker_initdirectly (withoutworker_process_init), simulating gevent/eventlet/threads — fails without the fix, passes with it.just test-ci— full suite green, 100% line coverage.just lint-ci— clean (ruff,ty,eof-fixer,check-planning).architecture/dependency-injection.mdupdated to describe both signal pairs;planning/changes/2026-07-21.01-open-root-all-pools.mdandplanning/releases/3.0.1.mdadded.🤖 Generated with Claude Code