Repository navigation
fix: close schedule poller Redis result consumers after dispatch - #44543
Closed
CodeWarriors0 wants to merge 4 commits into
Closed
CodeWarriors0 wants to merge 4 commits into
CodeWarriors0 wants to merge 4 commits into
Conversation
CodeWarriors0
requested review from
CourTeous33,
QuantumGhost and
laipz8200
as code owners
October 22, 2026 06:55
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44543 +/- ##
==========================================
- Coverage 89.05% 88.99% -0.06%
==========================================
Files 5616 5608 -8
Lines 337608 337460 -148
Branches 67539 67390 -149
==========================================
- Hits 300652 300319 -333
- Misses 31710 31900 +190
+ Partials 5246 5241 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Coverage follow-up:
The new-head CI run is pending; the production implementation is unchanged by this follow-up. |
2 of 5 tasks
Contributor
|
Hi @CodeWarriors0 , thanks for reporting this issue. We have merged a simpler fix by removing |
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.
Warning
Production impact: this issue caused more than 10,000 Redis connections to accumulate in my production environment.
This is the production observation that motivated the fix, not a count generated by the tests. Validation of the fix under production load is not claimed here.
Fixes #44542.
Problem
The scheduled-workflow poller dispatches due workflows through a Celery group without waiting for its result. In a long-lived gevent worker, the group's callbacks still start a Redis result drainer. Canceling a subscription does not stop that drainer, so its backend and connection can remain alive and accumulate over repeated dispatch batches.
Issue #44542 contains the affected environment and reproduction steps. Actual dispatches matter; empty polls do not exercise this path. Retained client IDs and increasing idle times are more useful than expecting a strict +1 in the server-wide connection count after each workflow execution.
Fix
Keep group dispatch but give each dispatch an explicitly owned Redis result backend. In
finally, stop its gevent drainer with a bounded wait, close PubSub and the private connection pool, clear result references, and restore the previous backend. Do not disconnect the broker or an initialized shared backend.Commit successful schedule updates before waiting for cleanup, so the cleanup wait does not extend the successful transaction's row-lock lifetime. No dependencies, configuration, or unrelated application code are changed.
CI follow-up
The first revision failed
Style Check / Python Stylebecause the no-new-getattr guard rejected two calls. Commit39fd25cfddreplaces those calls with Celery's existing backend accessor and an explicit gevent drainer type.The regression tests were also rewritten to meet the repository's testing policies: they instantiate real Celery, Redis, gevent, SQLAlchemy Session, and model objects, and patch boundary methods instead of adding Mock/MagicMock/SimpleNamespace constructors. No guard exemptions, disabled checks, or CI policy changes were added.
Verification
Final local validation on Python 3.13 with upstream's locked dependencies:
_dispatch_result_backend: 36/36 executable lines and 12/12 branches covered locally, with no coverage-policy changes.7e92273d5aadds synchronous PubSub/pool-close failure tests so these paths are also verified without gevent context switches.make type-check-core: passed.git diff --check: passed.The focused test command is:
Tests cover normal and exceptional cleanup, restoration of initialized/uninitialized backends, late AsyncResult destruction, shared/non-Redis bypass, unstarted/running/stopped drainers, and publication/SQLite commit failures. A separate subprocess runs real Celery/gevent groups and real Redis connection-pool/PubSub code over local socket pairs; it verifies SUBSCRIBE bytes, concurrent dispatch isolation, and socket closure. It does not connect to a Redis server.
Limits: the new-head GitHub CI must still complete. These tests are not a full worker/Redis integration, network-fault, or production-load validation. The production impact reported above is separate from the automated evidence.
Checklist
Fixes #44542.No user-facing documentation update or screenshots are applicable to this backend resource-lifecycle change. This contribution is AI-assisted; the actual checks and verification limits are disclosed above.
From DeepSeek Harness