Cancel the Dataflow job when a user kills the deferred task - #69586
Open
steveahnahn wants to merge 2 commits into
Open
Cancel the Dataflow job when a user kills the deferred task#69586steveahnahn wants to merge 2 commits into
steveahnahn wants to merge 2 commits into
Conversation
steveahnahn
force-pushed
the
dataflow-cancel-job-on-user-kill-deferred
branch
2 times, most recently
from
July 8, 2026 06:46
cadba9a to
f4df591
Compare
steveahnahn
marked this pull request as ready for review
July 8, 2026 21:02
steveahnahn
force-pushed
the
dataflow-cancel-job-on-user-kill-deferred
branch
from
July 10, 2026 23:05
f4df591 to
6e7fa45
Compare
aaron-y-chen
left a comment
Contributor
There was a problem hiding this comment.
Hi, thanks for the PR, very impressive :)
steveahnahn
force-pushed
the
dataflow-cancel-job-on-user-kill-deferred
branch
from
July 16, 2026 02:04
6e7fa45 to
54df2f5
Compare
Killing a deferred Dataflow task (mark-failed, clear or mark-succeeded) leaves the Dataflow job running: the trigger has no on_kill, so the user-kill cancellation the sibling BigQuery and Dataproc triggers already perform never happens, and a streaming pipeline keeps running and billing until someone notices in the Cloud console. Before the Airflow 3.3 trigger cancellation redesign the legacy path cancelled the job from inside the trigger, so this is also a behavior regression for deferrable users. Implement on_kill on TemplateJobStartTrigger following the merged BigQuery/Dataproc/EMR pattern, honoring the operator's drain_pipeline setting so streaming jobs are drained rather than cancelled when configured, exactly as the non-deferred kill path does. The hook is built and invoked inside a worker thread because the synchronous DataflowHook resolves its connection during construction, which must not run in the triggerer's event loop.
steveahnahn
force-pushed
the
dataflow-cancel-job-on-user-kill-deferred
branch
from
July 16, 2026 02:05
54df2f5 to
bd3f1bb
Compare
aaron-y-chen
approved these changes
Jul 20, 2026
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.
Problem
TemplateJobStartTrigger(templated/flex jobs) norDataflowStartYamlJobTrigger(YAML jobs) hason_kill; the BigQuery and Dataproc triggers in this provider already cancel in the same situation.on_killeven documents the gap: it "will not be called if a task instance is killed in a deferred state."Change
on_killto bothTemplateJobStartTriggerandDataflowStartYamlJobTrigger: checkscancel_on_kill,job_id,project_id, then cancels via the syncDataflowHook. Identical cancel path in both.drain_pipelineis honored, matching the non deferred kill path.sync_to_async):DataflowHookresolves its connection eagerly at construction, which must not run in the triggerer event loop. Construction inside thetrymeans a connection error is logged, not raised.End to end verification
deferred, jobJOB_STATE_RUNNING.on_kill:JOB_STATE_RUNNING->JOB_STATE_CANCELLING->JOB_STATE_CANCELLED(gcloud dataflow jobs list). Withcancel_on_kill=Falsethe job keeps running.The YAML trigger uses the identical
DataflowHook.cancel_jobpath proven above, so the e2e run covers its cancel mechanism; it is additionally unit tested.Tests
on_killtests for both triggers: cancel,drain_pipelinehonored, no ops (cancel_on_kill=False, missingjob_id/project_id), hook errors swallowed, hook construction errors swallowed; plus operator threading ofdrain_pipelineinto the trigger.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines