Repository navigation
Keep a finished result when a revoke arrives for the task - #10679
Conversation
Since celery#9869 the revoke command writes REVOKED to the result backend for every id the worker is not currently running. When a chord header fails and the body is a group, _handle_group_chord_error() revokes the body ids and stores FAILURE for each of them; the revoke is a broadcast, so the worker's main process writes REVOKED a few milliseconds later and replaces that FAILURE. Callers then get TaskRevokedError instead of the header's exception, depending on which write lands last. Skip the REVOKED write when the backend already holds a ready state for the task, and store the chord failures before broadcasting the revoke so that check always sees them. Pending tasks, the case celery#9869 was about, are still marked.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10679 +/- ##
=======================================
Coverage 89.28% 89.28%
=======================================
Files 153 153
Lines 20394 20397 +3
Branches 2430 2431 +1
=======================================
+ Hits 18209 18212 +3
Misses 1881 1881
Partials 304 304
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
there is also consumers test failures beside this one |
|
my AI analysis: The job fails because the smoke test expects prefetch-reduction logs, but the worker correctly skips prefetch reduction when the broker uses per-consumer QoS. The decisive log is: This branch is implemented in
The failing tests unconditionally expect those messages in Recommended fixRun these prefetch-reduction tests with a classic RabbitMQ queue, where @pytest.fixture
def default_worker_app(default_worker_app: Celery) -> Celery:
app = default_worker_app
app.conf.worker_prefetch_multiplier = WORKER_PREFETCH_MULTIPLIER
app.conf.worker_concurrency = WORKER_CONCURRENCY
app.conf.worker_enable_prefetch_count_reduction = True
# These tests verify global basic.qos prefetch reduction.
# Quorum/per-consumer QoS cannot exercise that behavior.
app.conf.task_default_queue_type = "classic"
app.conf.visibility_timeout = 3600
if app.conf.broker_url.startswith("redis"):
app.conf.broker_transport_options = {
"visibility_timeout": app.conf.visibility_timeout,
"polling_interval": 1,
}
if app.conf.result_backend.startswith("redis"):
app.conf.result_backend_transport_options = {
"visibility_timeout": app.conf.visibility_timeout,
"polling_interval": 1,
}
return appIf the pytest-Celery worker queue is declared independently of from kombu import Queue
app.conf.task_queues = (
Queue(
"celery",
queue_arguments={"x-queue-type": "classic"},
),
)Use the actual worker queue name if pytest-Celery generates a dedicated queue. Alternative test correctionIf the intended broker configuration is quorum queues, the tests should validate the new supported behavior instead of expecting reduction/restoration logs: celery_setup.broker.restart()
celery_setup.worker.assert_log_exists(
"Skipping prefetch count reduction after connection restart "
"because per-consumer QoS (apply_global=False) is in effect"
)The existing assertions should then be conditional on queue QoS mode. Do not remove the The workflow itself merely dispatches the smoke suite through |
|
should we fix the consumer test failure in a separate pr? or you prefer doin it here? |
|
@auvipy This one comes from Kombu: celery/kombu#2481 makes |
|
sure please! no prob! |
|
Opened celery/kombu#2665 for the Kombu side. |
|
@auvipy Follow-up on the consumer failures: I had this backwards. RabbitMQ 4.3 denies |
|
I’d prefer adapting the consumer tests in a separate PR to expect the “Skipping prefetch count reduction” path on RabbitMQ 4.3+. Reimplementing reduction for per-consumer QoS by canceling and re-consuming would be considerably more invasive and risky: The separate PR should make the expectations conditional on the broker/QoS mode and retain coverage for global QoS where it is still supported. I’d also keep this PR focused on preserving finished chord results and avoid coupling it to the consumer-test changes. |
|
although right now Im not fully sure which approach will be best in long term |
auvipy
left a comment
There was a problem hiding this comment.
can you check if anything else can be done here? or can we do anything to harden the tests? going to merge this separately
Cover the revoke guard for every ready and unready state and for a failing state lookup, and check that _handle_group_chord_error() stores all the failures before it broadcasts the revoke, since the guard depends on that order.
|
@auvipy Pushed one more test-only commit here (63d65d1): the guard is now checked for every READY and UNREADY state plus a failing state lookup, and there's a test that |
Since #9869 the revoke command writes
REVOKEDto the result backend for every id the worker isn't currently running. When a chord header fails and the body is a group,_handle_group_chord_error()revokes the body ids and storesFAILUREfor each of them; the revoke is a broadcast, so the worker's main process writesREVOKEDa few milliseconds later and replaces thatFAILURE. Whichever write lands last wins, and callers getTaskRevokedErrorinstead of the header's exception. This is what makestest_chord_error_propagation_with_different_body_types[body is a group]fail on #10677: Kombu 5.7.0a1 only changes the broadcast timing enough for the wrong write to land last on CI.Skip the
REVOKEDwrite when the backend already holds a ready state for the task, and store the chord failures before broadcasting the revoke so that check always sees them. Pending tasks, the case #9869 was about, are still marked. The check is one extra backend read per revoked id in the control command.Checked with Kombu 5.7.0a1 pinned: the
body is a groupcase passes 3 out of 3 runs where it failed every time before, all four body types pass on both brokers, andt/unit/workeris unchanged apart from the new test.Fixes the smoke failure that came with the Kombu 5.7.0a1 bump (#10677).