Skip to content

Fix DagProcessorJob crash on orphan processor kill - #69523

Open
hkc-8010 wants to merge 13 commits into
apache:mainfrom
hkc-8010:fix/64959-dag-processor-orphan-kill
Open

Fix DagProcessorJob crash on orphan processor kill#69523
hkc-8010 wants to merge 13 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

Venkat Saddala and others added 6 commits July 7, 2026 10:49
…phan kill

After SIGKILL, stale socket registrations on the shared selector cause
the next select() callback to write to an already-closed log handle.
Add _deregister_processor_sockets() to clean up sockets before closing
the handle, and guard target.log() in the supervisor against ValueError.

Closes: apache#64959
Re-add test_deregister_processor_sockets_suppresses_already_unregistered
and test_deregister_processor_sockets_suppresses_close_error which
directly exercise the KeyError and OSError suppression paths in
_deregister_processor_sockets.
`_deregister_processor_sockets` uses `contextlib.suppress` in three
places but the module never imported `contextlib`, which `ruff`
(F821) flags as an undefined name. Caught while rebasing PR apache#65002
onto current main; the PR's own CI run predates this code path.
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 8, 2026
@eladkal eladkal added this to the Airflow 3.3.1 milestone Jul 15, 2026
@eladkal eladkal added type:bug-fix Changelog: Bug Fixes backport-to-v3-3-test Backport to v3-3-test labels Jul 15, 2026
@vatsrahul1001

Copy link
Copy Markdown
Contributor

LGTM! can we merged post review from code owners

Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
Comment thread task-sdk/src/airflow/sdk/execution_time/supervisor.py Outdated
Comment thread task-sdk/src/airflow/sdk/execution_time/supervisor.py Outdated
@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.

from cadwyn import VersionChange


class TrackDagProcessorSocketCleanupOwnership(VersionChange):

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.

Why do we need the VersionChange here? I don't see any downstream consumer for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:DAG-processing area:task-sdk backport-to-v3-3-test Backport to v3-3-test ready for maintainer review Set after triaging when all criteria pass. 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

6 participants