Skip to content

Fix LocalExecutor crash on non-picklable exceptions (e.g. httpx.HTTPStatusError) - #64485

Closed
Pranaykarvi wants to merge 3 commits into
apache:mainfrom
Pranaykarvi:fix/localexecutor-unserializable-exception-clean
Closed

Pranaykarvi wants to merge 3 commits into
apache:mainfrom
Pranaykarvi:fix/localexecutor-unserializable-exception-clean

Conversation

@Pranaykarvi

Copy link
Copy Markdown
Contributor

Closes #64476

When LocalExecutor runs a task in a subprocess, exceptions are passed back via multiprocessing.Queue using pickle. Some exceptions like httpx.HTTPStatusError are not pickle-safe, causing:

TypeError: HTTPStatusError.__init__() missing 2 required keyword-only arguments: 'request' and 'response'

This crashes the scheduler loop and takes down the entire scheduler pod.

Root Cause

Raw exception objects were placed directly onto the result queue:

output.put((key, TaskInstanceState.FAILED, e))

Fix

Wrap the exception in a plain Exception before queuing:

safe_exc = Exception(f"{type(e).__name__}: {str(e)}\n{traceback.format_exc()}")
output.put((key, TaskInstanceState.FAILED, safe_exc))

Applied to both ExecuteTask and ExecuteCallback branches.

Impact

  • Scheduler no longer crashes on non-picklable exceptions
  • Full debugging info preserved
  • Minimal change, no other executor behaviour affected

@boring-cyborg boring-cyborg Bot added the area:Executors-core LocalExecutor & SequentialExecutor label Mar 30, 2026
@eladkal

eladkal commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

@Pranaykarvi please explain how you verified the issue present only in LocalExecutor?

@eladkal eladkal added this to the Airflow 3.2.1 milestone Mar 31, 2026
@Pranaykarvi

Pranaykarvi commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@eladkal , Thanks for raising this!

From what I observed, this issue is tied specifically to LocalExecutor because it uses multiprocessing.Queue to send results (including exceptions) from worker subprocesses back to the scheduler. That means everything passed through needs to be pickleable and exceptions like httpx.HTTPStatusError aren’t, which leads to the crash.

Other executors (like KubernetesExecutor or CeleryExecutor) don’t rely on multiprocessing queues in the same way they use external systems (like the K8s API, message brokers, or the metadata DB) to communicate task results, so they don’t run into this problem.

I reproduced the issue using LocalExecutor and traced it through the multiprocessing flow, which is where the failure happens.

@kaxil

kaxil commented Mar 31, 2026

Copy link
Copy Markdown
Member

Wasn't this already fixed in #48517 !

@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 Apr 1, 2026
@kaxil
kaxil requested a review from Copilot April 2, 2026 00:42

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

Fixes a LocalExecutor failure mode where worker subprocess exceptions may be unpicklable (e.g. httpx.HTTPStatusError), which can crash the scheduler when the exception object is sent back over a multiprocessing.Queue.

Changes:

  • Import traceback and wrap worker exceptions into a pickle-safe Exception containing type/message + formatted traceback.
  • Apply the same wrapping behavior to both task execution and callback execution failure paths.

@Pranaykarvi

Copy link
Copy Markdown
Contributor Author

@kaxil @eladkal All 6 Copilot review comments have been addressed:

  • Extracted _safe_exception_for_ipc() helper to avoid duplication
  • Returns (type, message) tuple instead of wrapped Exception
  • Removed traceback import and format_exc() overhead
  • Forwarded exc_info through _read_results() → change_state(info=)
  • Added regression test for non-picklable exceptions

Ready for re-review!

@kaxil

kaxil commented Apr 2, 2026

Copy link
Copy Markdown
Member

Wasn't this already fixed in #48517 !

Did you check this? I am trying to figure out what changed between then and now

@Pranaykarvi

Copy link
Copy Markdown
Contributor Author

@kaxil @eladkal Thanks for the pointer to #48517 — you're right,
this is a duplicate. #48517 already fixes the exact same
multiprocessing.Queue pickle crash in LocalExecutor by wrapping
non-picklable exceptions before queuing them.

I've verified that #48517 was merged into main on March 29, 2025
and covers the same ServerResponseError/httpx pickling failure
reported in the original issue #64476.

Closing this PR as a duplicate. Apologies for the noise!

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. type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running Python DAG crashes Scheduler pod

5 participants