Skip to content

Drain result_queue in LocalExecutor to prevent process join deadlock - #67881

Merged
o-nikolas merged 4 commits into
apache:mainfrom
SakshamKapoor2911:fix-local-executor-deadlock
Jul 2, 2026
Merged

o-nikolas merged 4 commits into
apache:mainfrom
SakshamKapoor2911:fix-local-executor-deadlock

Conversation

@SakshamKapoor2911

@SakshamKapoor2911 SakshamKapoor2911 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

closes: #67870

Description

This PR fixes a deadlock in the LocalExecutor during executor shutdown (end()).

Currently, the executor calls proc.join() on active worker processes. However, if a worker has written enough results to the result_queue to fill the OS-level pipe buffer (typically 64KB), the worker process blocks indefinitely on its put() call.
Because the parent scheduler process is blocked on the unbounded proc.join() and not reading from result_queue, a classic multiprocessing deadlock occurs. The scheduler hangs indefinitely, stopping heartbeats and preventing systemd/Kubernetes from restarting the process (as it never exits).

Changes

  1. Draining during Join: Updated the shutdown loop in LocalExecutor.end() to continuously drain the result_queue using _read_results() while waiting for worker processes to join with a small timeout.
  2. Robust Queue Reading: Wrapped the queue drainage loop in _read_results() with a try/except (OSError, EOFError) block to gracefully handle cases where pipes are already broken or closed during task exit.
  3. Forced Terminate: Implemented the LocalExecutor.terminate() method to forcefully kill any remaining workers when a hard stop is requested.

Context

This contribution was created as part of the required capstone of the CodePath AI301 course, where students learn how to make responsible and effective use of generative AI tools for open-source software contributions.


Was generative AI tooling used to co-author this PR?
  • Yes (Antigravity IDE powered by Gemini)

Generated-by: Antigravity IDE (Gemini) following the guidelines



Note

✅ Ready for review · @SakshamKapoor2911 → @potiuk · 2026-06-12 13:30 UTC

Thanks @SakshamKapoor2911 — all checks are green and this PR is marked ready for maintainer review. The ball is with the maintainers now; a maintainer will take the next look.

Automated triage — may be imperfect.

Copilot AI review requested due to automatic review settings June 2, 2026 00:24
@boring-cyborg boring-cyborg Bot added the area:Executors-core LocalExecutor & SequentialExecutor label Jun 2, 2026
@boring-cyborg

boring-cyborg Bot commented Jun 2, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes a potential deadlock in LocalExecutor shutdown where workers blocked on writing to a full result_queue would never exit, hanging the scheduler. Also makes terminate() actually terminate worker processes.

Changes:

  • Drain result_queue while waiting for workers to join in end(), with KeyboardInterrupt/SystemExit fallback that force-terminates workers.
  • Harden _read_results against OSError/EOFError from a closed/broken queue.
  • Implement terminate() to forcefully terminate all worker processes (previously a no-op).

Comment thread airflow-core/src/airflow/executors/local_executor.py Outdated
Comment thread airflow-core/src/airflow/executors/local_executor.py Outdated
Comment thread airflow-core/src/airflow/executors/local_executor.py Outdated
Comment thread airflow-core/src/airflow/executors/local_executor.py
@SakshamKapoor2911

SakshamKapoor2911 commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor Author

@potiuk Fixed the Ruff pre-commit hook failures on this PR by addressing the following two lint issues:

  1. Ruff SIM105: Replaced the try-except-pass block when closing worker processes with contextlib.suppress(ValueError).
  2. Ruff D401: Rewrote the docstring of the terminate method to begin with an imperative verb ("Terminate all worker processes..." instead of "Forcefully terminate...").

All local checks now pass successfully and should pass the CI tests.

@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 Jun 12, 2026
Comment thread airflow-core/src/airflow/executors/local_executor.py Outdated
Comment thread airflow-core/src/airflow/executors/local_executor.py Outdated
Comment thread airflow-core/src/airflow/executors/local_executor.py
@SakshamKapoor2911
SakshamKapoor2911 force-pushed the fix-local-executor-deadlock branch from 33cd755 to 5684360 Compare June 27, 2026 14:36

@o-nikolas o-nikolas 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.

Thanks for the updates, as long as the CI goes green it looks good to me

@SakshamKapoor2911 SakshamKapoor2911 changed the title fix: drain result_queue in LocalExecutor to prevent process join dead… Drain result_queue in LocalExecutor to prevent process join deadlock Jun 30, 2026
@SakshamKapoor2911
SakshamKapoor2911 force-pushed the fix-local-executor-deadlock branch from 5684360 to 28fa007 Compare June 30, 2026 21:14
@SakshamKapoor2911

Copy link
Copy Markdown
Contributor Author

@o-nikolas could you please approve the pending GitHub Actions workflows for the latest push?

I fixed the single CI failure by removing the Conventional Commits-style fix: prefix from the PR title and rewriting the branch commit subjects. This was metadata-only; the code tree did not change. The latest head is 28fa007d66.

On the previous run, the only failed job was CI image checks / Static checks; all other executed jobs passed, with the remaining jobs skipped by CI selection.

@o-nikolas

Copy link
Copy Markdown
Contributor

@o-nikolas could you please approve the pending GitHub Actions workflows for the latest push?

I fixed the single CI failure by removing the Conventional Commits-style fix: prefix from the PR title and rewriting the branch commit subjects. This was metadata-only; the code tree did not change. The latest head is 28fa007d66.

On the previous run, the only failed job was CI image checks / Static checks; all other executed jobs passed, with the remaining jobs skipped by CI selection.

Done!

@SakshamKapoor2911

Copy link
Copy Markdown
Contributor Author

@o-nikolas CI is green now, including the previously failing CI image checks / Static checks. Thanks again for approving the workflows. Would you mind merging this when you get a chance?

@o-nikolas
o-nikolas merged commit 670785d into apache:main Jul 2, 2026
77 checks passed
@boring-cyborg

boring-cyborg Bot commented Jul 2, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

SakshamKapoor2911 added a commit to SakshamKapoor2911/airflow that referenced this pull request Jul 27, 2026
…alExecutor

Call _read_results() before each activity_queue.put() in _process_workloads
so workers blocked on a full result_queue pipe can resume reading from
activity_queue, preventing the circular deadlock described in apache#70526.

This is the dispatch-side equivalent of the fix applied to end() in apache#67881.
SakshamKapoor2911 added a commit to SakshamKapoor2911/airflow that referenced this pull request Jul 27, 2026
…alExecutor

Call _read_results() before each activity_queue.put() in _process_workloads
so workers blocked on a full result_queue pipe can resume reading from
activity_queue, preventing the circular deadlock described in apache#70526.

This is the dispatch-side equivalent of the fix applied to end() in apache#67881.
@pierrejeambrun

pierrejeambrun commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

@o-nikolas should this be included and backported in 3.3.2? Also #70545 depends on that too.

@o-nikolas

Copy link
Copy Markdown
Contributor

@o-nikolas should this be included and backported in 3.3.2? Also #70545 depends on that too.

@pierrejeambrun I don't feel too strongly about it personally. But since the call has been made for #70545 then we should pull this one in as well I reckon.

CC @vatsrahul1001

@pierrejeambrun

pierrejeambrun commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Actually after second consideration I've moved that to 3.4.0 so it has time to sink in before 3.4.0 (and spend some time under testing before being released). But i'm ok if we want this in 3.3.2.

@o-nikolas

Copy link
Copy Markdown
Contributor

Actually after second consideration I've moved that to 3.4.0 so it has time to sink in before 3.4.0 (and spend some time under testing before being released). But i'm ok if we want this in 3.3.2.

Yeah, I think that's a good call @pierrejeambrun!

SakshamKapoor2911 added a commit to SakshamKapoor2911/airflow that referenced this pull request Oct 7, 2026
…e dispatch deadlock

Fixes the runtime/dispatch-path deadlock reported in apache#70526: during
_process_workloads the scheduler could block in activity_queue.put() while workers
were blocked writing results into a full result_queue pipe, a circular wait. Draining
the result queue before each put breaks the cycle. The end()/join path is already
handled by apache#67881; this covers normal dispatch. Adds a call-order unit test and a
bounded real-queue regression test.
ashb pushed a commit to SakshamKapoor2911/airflow that referenced this pull request Oct 15, 2026
…e dispatch deadlock

Fixes the runtime/dispatch-path deadlock reported in apache#70526: during
_process_workloads the scheduler could block in activity_queue.put() while workers
were blocked writing results into a full result_queue pipe, a circular wait. Draining
the result queue before each put breaks the cycle. The end()/join path is already
handled by apache#67881; this covers normal dispatch. Adds a call-order unit test and a
bounded real-queue regression test.
vatsrahul1001 pushed a commit that referenced this pull request Oct 18, 2026
…e dispatch deadlock (#70545)

Fixes the runtime/dispatch-path deadlock reported in #70526: during
_process_workloads the scheduler could block in activity_queue.put() while workers
were blocked writing results into a full result_queue pipe, a circular wait. Draining
the result queue before each put breaks the cycle. The end()/join path is already
handled by #67881; this covers normal dispatch. Adds a call-order unit test and a
bounded real-queue regression test.
vatsrahul1001 pushed a commit that referenced this pull request Oct 18, 2026
…event runtime dispatch deadlock (#70545) (#74949)

Fixes the runtime/dispatch-path deadlock reported in #70526: during
_process_workloads the scheduler could block in activity_queue.put() while workers
were blocked writing results into a full result_queue pipe, a circular wait. Draining
the result queue before each put breaks the cycle. The end()/join path is already
handled by #67881; this covers normal dispatch. Adds a call-order unit test and a
bounded real-queue regression test.
(cherry picked from commit b00cfeb)

Co-authored-by: Saksham Kapoor <sakshamkapoor2911@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Oct 20, 2026
…event runtime dispatch deadlock (#70545) (#74949)

Fixes the runtime/dispatch-path deadlock reported in #70526: during
_process_workloads the scheduler could block in activity_queue.put() while workers
were blocked writing results into a full result_queue pipe, a circular wait. Draining
the result queue before each put breaks the cycle. The end()/join path is already
handled by #67881; this covers normal dispatch. Adds a call-order unit test and a
bounded real-queue regression test.
(cherry picked from commit b00cfeb)

Co-authored-by: Saksham Kapoor <sakshamkapoor2911@gmail.com>
SameerMesiah97 pushed a commit to SameerMesiah97/airflow-oss-sm97 that referenced this pull request Oct 27, 2026
…e dispatch deadlock (apache#70545)

Fixes the runtime/dispatch-path deadlock reported in apache#70526: during
_process_workloads the scheduler could block in activity_queue.put() while workers
were blocked writing results into a full result_queue pipe, a circular wait. Draining
the result queue before each put breaks the cycle. The end()/join path is already
handled by apache#67881; this covers normal dispatch. Adds a call-order unit test and a
bounded real-queue regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Executors-core LocalExecutor & SequentialExecutor ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

5 participants