Repository navigation
Fix repeated cancellation aborting trigger on_kill grace period - #76210
Open
hussein-awala wants to merge 1 commit into
Open
hussein-awala wants to merge 1 commit into
hussein-awala wants to merge 1 commit into
Conversation
Clearing a deferred task, or marking it failed or succeeded, makes the triggerer cancel its trigger and run on_kill() for up to [triggerer] on_kill_timeout (30 seconds by default). The supervisor keeps sending the trigger id in every state sync, about once per second, until the trigger reports finished, and the runner cancelled the trigger task again on each of those syncs. The second cancellation landed inside the awaited on_kill() and aborted it, so cleanup such as deleting a pod or stopping a remote job was cut off after roughly one second and could leave external resources running. Those repeats were also what stopped a trigger that lost its first cancellation, for example to a library that swallows CancelledError or to asyncio.wait_for() on Python 3.11, so a trigger task that outlives the on_kill() grace still needs to be cancelled again.
This was referenced Nov 3, 2026
seanghaeli
approved these changes
Nov 3, 2026
Contributor
|
Looks good. Nothing else needed here, just a note for my own trigger work, since |
This branch has not been deployed
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.
Clearing a deferred task, or marking it failed or succeeded, cancels its trigger and runs
on_kill()for up to[triggerer] on_kill_timeout(30 s by default). The supervisor re-sends the id in every sync until the trigger finishes (L656-L661), and the runner cancels the task again on each, about once per second. The secondCancelledErrorlands insideon_kill(), where a branch written for shutdown swallows it (L1845-L1855), so cleanup such as deleting a pod stops after about a second, possibly leaving the resource running. Record when each trigger was cancelled, and cancel it again only afteron_kill_timeoutplus a 5 s margin.related: #76209
No new configuration, database or protocol change. Only delivered cancels are recorded, so one arriving before the trigger task exists applies on the next re-send. The id is forgotten when the trigger finishes, so a reused id can be cancelled. The supervisor never moves an id between
cancelling_triggersandreleasing_triggers, so one record serves both.A cancelled trigger now counts in the
triggers.runningandtriggerer.capacity_leftgauges whileon_kill()runs; claiming new triggers counts database rows and is unaffected. A task that swallows its first cancellation is cancelled again after 35 s by default instead of about a second. The 5 s margin covers logging andcleanup()aroundon_kill(). Shutdown is unaffected.#73702 (Glue) and #74358 (BigQuery) rely on
on_kill()finishing.v3-4-testhas the samecancel_triggers();v3-3-testhas onlyto_canceland needs a small manual change.A later PR planned in #76209 wakes the runner on trigger activity (up to about 20 syncs/s); without this fix, event traffic there cuts
on_kill()off after about 50 ms, so this should merge first. #76218 touches the samecancel_triggers()/cleanup_finished_triggers()code, replacing the cleanup scan with a done-callback queue; whichever merges later is rebased and keeps the forget-on-finish step.In a runner-level benchmark driving the real
TriggerRunnermethods, with a trigger whoseon_kill()needs 3.0 s and a cancel re-sent every 0.25 s:on_kill()completedon_kill()start to task endBefore, the second cancel aborted
on_kill()about 0.25 s in and the next poll saw the task end. After, the cancel is re-sent longer only becauseon_kill()now completes; only the first is delivered. Medians of five rounds, alternating which side runs first; these paths issue no SQL. Cancel rows matched every round; the control moved +0.5%, within noise. Local measurements, not end-to-end latency.test_repeated_cancel_syncs_do_not_abort_on_killre-sends the cancel while a realrun_trigger()task is held inon_kill()by an event the test releases. Others cover redelivery after the grace period for both queues, a cancel arriving before its trigger task exists, and a reused id. Every new test fails against the previous logic.Validation:
breeze verifylists passed on a local merge of the nine PRs opened together under Improve triggerer performance (AI-assisted deep dive) #76209: core DB tests of the API, Always, CLI, Core, Other and Serialization groups on SQLite (12,254 run, no failures), core non-DB tests (5,582 passed) and theapache-airflowdocumentation build.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines
🤖 Generated with Claude Code