Skip to content

Fix DagProcessorJob crash on orphan processor kill - #69523

Merged
vatsrahul1001 merged 2 commits into
apache:mainfrom
hkc-8010:fix/64959-dag-processor-orphan-kill
Sep 10, 2026
Merged

vatsrahul1001 merged 2 commits into
apache:mainfrom
hkc-8010:fix/64959-dag-processor-orphan-kill

Conversation

@hkc-8010

@hkc-8010 hkc-8010 commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Prevent DagProcessorJob from crashing with ValueError: write to closed file
when orphaned or timed-out dag processor subprocesses are killed.

This change drains and deregisters processor log sockets before closing the
logger handle in DagFileProcessorManager, and narrows supervisor-side
ValueError handling so only the closed-log-file case is skipped.

It also adds regression coverage for:

  • orphan and timeout kill ordering
  • socket deregistration and drain behavior
  • supervisor handling of closed logger targets

closes: #64959


Was generative AI tooling used to co-author this PR?
  • Yes — OpenAI Codex (GPT-5)

Generated-by: OpenAI Codex (GPT-5) following the guidelines

@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Jul 8, 2026
@eladkal eladkal added this to the Airflow 3.3.1 milestone Jul 15, 2026
@vatsrahul1001

Copy link
Copy Markdown
Contributor

LGTM! can we merged post review from code owners

@hkc-8010
hkc-8010 requested a review from kaxil August 3, 2026 03:26

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

@hkc-8010
hkc-8010 force-pushed the fix/64959-dag-processor-orphan-kill branch from 1d79e80 to 9de1c63 Compare August 23, 2026 09:45
@hkc-8010
hkc-8010 requested a review from jason810496 August 23, 2026 09:56
@eladkal
eladkal force-pushed the fix/64959-dag-processor-orphan-kill branch from 9de1c63 to bb538b7 Compare August 29, 2026 14:28
@vatsrahul1001

Copy link
Copy Markdown
Contributor

@amoghrajesh can you help review this?

@uranusjr uranusjr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit.

After a processor is SIGKILLed its sockets stay registered on the shared
selector, so the next select() callback writes to an already-closed log
handle and the job dies with "ValueError: write to closed file".

Add WatchedSubprocess.cleanup_sockets_after_kill() to drain the log-bearing
sockets, run their close callbacks and unregister them, and call it from
DagFileProcessorProcess.close(). Request sockets are closed without being
drained so no request frames get dispatched after the kill.

Also route supervisor log writes through _log_to_target() so a logger whose
handle is already closed is skipped instead of taking the process down.

closes: apache#64959
@hkc-8010
hkc-8010 force-pushed the fix/64959-dag-processor-orphan-kill branch from bb538b7 to 0fb21a8 Compare September 10, 2026 07:16

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vatsrahul1001
vatsrahul1001 merged commit 6d9cc2e into apache:main Sep 10, 2026
106 of 107 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-3-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 6d9cc2e v3-3-test

This should apply the commit to the v3-3-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

vatsrahul1001 added a commit that referenced this pull request Sep 10, 2026
After a processor is SIGKILLed its sockets stay registered on the shared
selector, so the next select() callback writes to an already-closed log
handle and the job dies with "ValueError: write to closed file".

Add WatchedSubprocess.cleanup_sockets_after_kill() to drain the log-bearing
sockets, run their close callbacks and unregister them, and call it from
DagFileProcessorProcess.close(). Request sockets are closed without being
drained so no request frames get dispatched after the kill.

Also route supervisor log writes through _log_to_target() so a logger whose
handle is already closed is skipped instead of taking the process down.

closes: #64959


(cherry picked from commit 6d9cc2e)

Co-authored-by: Hemkumar Chheda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dag-processor area:task-sdk ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DAG Processor Job crashes with "ValueError: write to closed file" — race condition in terminate_orphan_processes between SIGKILL and log drain

9 participants