Repository navigation
Description
Tasks that make outbound HTTPS calls (cloud-provider hooks/operators built on google-auth/urllib3/requests — e.g. GKEStartPodOperator or a Google-provider sensor) can hang indefinitely with no further progress. execution_timeout does not recover the task (thats a separate, related problem tracked in #53337).
py-spy dumps of a hung worker, taken minutes apart, confirm that every active thread in the process the task's own thread, plus unrelated background threads are frozen at the identical point, each building a fresh SSLContext for a different remote host:
__new__ (ssl.py:440)
create_urllib3_context (urllib3/util/ssl_.py:252)
_ssl_wrap_socket_and_match_hostname (urllib3/connection.py:928)
connect (urllib3/connection.py:812)
...
That rules out a network-specific hang and SSLContext construction itself is blocked process-wide.
The task subprocess is created via a bare os.fork() in ActivitySubprocess.start() (task-sdk/src/airflow/sdk/execution_time/supervisor.py), since _should_use_exec() only returns True on darwin:
_FORK_EXEC_PLATFORMS = {"darwin"}
def _should_use_exec() -> bool:
return sys.platform in _FORK_EXEC_PLATFORMSThe supervisor process is multithreaded by the time any task starts (OTel exporter threads, per-connection google-auth background refresh threads, an OpenLineage listener, etc. are normal background threads in a long-running worker). os.fork() copies the address space. Still, only the calling thread survives in the child. If any sibling thread was midway through OpenSSL's global lock (taken inside SSL_CTX_new(), which every ssl.SSLContext() call goes through) at the exact instant of the fork, the child inherits that lock already held, permanently & the thread that held it no longer exists to release it. Every later SSLContext construction in that child, from any thread, then blocks forever.
Steps to reproduce (a timing race, won't reproduce every attempt):
- Run a task via the Task SDK on Linux, using a hook/operator that opens outbound HTTPS connections.
- Ensure the supervisor has several concurrent background threads also doing HTTPS/TLS work at task-launch time (OTel exporter, one or more
google-authCredentialsobjects with regional-access-boundary refresh threads, OpenLineage listener). - Launch tasks in volume. Intermittently, a task hangs forever with no log output past its last HTTPS-triggering line.
py-spy dump --pid <hung-pid> --subprocesseswhile hung, every active thread shows the samessl.py:440frame.
What do you think should happen instead?
The task should complete or eventually be killed and retried — not hang indefinitely due to C-library lock state inherited from an unrelated background thread.
Same hazard class already fixed for macOS (#64874, #65691 — Objective-C runtime corruption after bare fork()) and hit again independently on Linux (#65942/#65943 — Edge Worker forking a 22-thread process, corrupting Python's own import-lock state). Here the poisoned lock is OpenSSL's, and the affected fork is the Task SDK's own ActivitySubprocess.start(), not an executor-level fork — so the existing _should_use_exec() gate doesn't cover it, since the original macOS fix's reasoning ("Linux's resolver has no ObjC dependency") is specific to that hazard and doesn't generalize to OpenSSL's own fork-unsafe locking.
Following the Edge Worker precedent (#65943), a plausible fix shape is an opt-in "fresh interpreter instead of bare fork" setting for ActivitySubprocess.start() on Linux, defaulting to current behavior to avoid a blanket performance regression — open question for maintainers whether that reuses execute_tasks_new_python_interpreter or needs a dedicated setting.
More info
- Related but distinct: Handle task timeouts (
execution_timeout) at supervisor #53337 (movingexecution_timeoutenforcement to the supervisor) would let a hang like this get killed and retried automatically — valuable, but doesn't fix the hang itself. - Prior art for this hazard class: Fix macOS
SIGSEGVin task execution by usingfork+exec#64874, Extend macOS fork+exec fix to DAG processor and triggerer #65691 (macOS/ObjC), Edge worker_launch_jobcorrupts import state on Python 3.12 — fork() in multi-threaded process inherits stale import locks #65942/Allow using fresh interpreter besides fork() in Edge Worker #65943 (Linux/Edge Worker, Python import locks). CPython itself emitsDeprecationWarning: This process is multi-threaded, use of fork() may lead to deadlocks in the childin this exact scenario.
Activity
slice-soupam commentedon Sep 8, 2026
The machinery to fix this already exists on
main— it's just gated off for Linux:start()canos.execva fresh interpreter right afteros.fork(). It was added for macOS's ObjC fork-unsafety (#65691), but it's the right remedy here too:execvreplaces the child's address space, so an OpenSSL mutex left locked by a thread that doesn't exist in the child can't survive into it. And it's not new code — it already carries the task runner, DAG processor and triggerer on macOS, socketpair/FD handoff and process groups included.So: reuse it on Linux rather than add a second spawn mechanism. The catch is that
execforfeits copy-on-write sharing of the parent's imported Airflow, so each child pays a fresh interpreter start plus full re-import — in both latency (~1-3s) and RSS, since nothing is shared with the parent any more. That cost is per-fork, so it scales with fork rate, and the fork rate differs by three orders of magnitude across components:High concurrent task load. Worst case. Every task instance pays the re-import, and because COW sharing is gone, each concurrent child now holds its own full copy of Airflow — so worker RSS grows with concurrency instead of staying near-flat. Short tasks are hit hardest, since the overhead is a fixed cost against a small payload. Note the perverse incentive: deadlock probability rises with parent thread activity, so the deployments that most need this fix are exactly the ones that pay most for it.
High DAG file count. Also significant, and I want to correct something I'd assumed: the DAG processor forks once per file per parse cycle (
_create_process, bounded byparsing_processes). With thousands of files, adding an interpreter start to every parse stretches the whole loop, and longer loops mean staler DAGs and later scheduling. Re-import is only cheap relative to a slow parse; across many fast ones it dominates.Triggerer. Forks once at startup. Overhead is unmeasurable.
Which suggests gating by fork rate rather than by platform alone:
Component | Fork rate | Proposal -- | -- | -- Triggerer | once | enable on Linux unconditionally DAG processor | per file, per cycle | config-gated, default off Task execution | per task instance | config-gated, default offairflow.sdk.configuration.confis already the SDK-side accessor and[workers]an existing SDK-visible section, so no new config plumbing. Follows themp_forkserver_preloadprecedent of exposing a start-method tradeoff rather than hardcoding it.Pros
execution_timeout, which only kills an already-lost task and can't cover the pre-execute()window).Cons
running, no logs, no heartbeat progress) in the option description.Longer term the cleaner answer is to not fork from a threaded parent at all — a
forkserverforked before any threads start removes the entire inherited-lock class and amortises the import across children, which would address the high-concurrency cost too. Bigger change; shouldn't block the mitigation above.Happy to put up a PR for the split above if the direction seems right.
ashb commentedon Sep 9, 2026
In Airflow 2 we had a config option to say whether to use fork or exec for running tasks -- we could bring that back, as this is only a problem in a small number of deployments -- the vast majority are fine.
kaxil commentedon Sep 9, 2026
#72164 should mostly solve it
Allow opting into fork+exec task processes via execute_tasks_new_pyth…
seanmuth commentedon Sep 21, 2026
Also related issue,
fork+execdoesn't guard against fork-unsafeatforkhandlers, such as thelogging.debug(...)calls in datadogpy: DataDog/datadogpy#989Use os.posix_spawn instead of fork+exec in the task-sdk supervisor
Use `os.posix_spawn` instead of fork+exec in the task-sdk supervisor (#…