airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Airflow 3.3.2: LocalExecutor workers and DAG Processor child processes hang when OpenTelemetry is enabled

Open zoomingrocket opened this issue 2 months ago • 10 comments

Under which category would you file this issue?

Providers

Apache Airflow version

3.3.2

What happened and how to reproduce it?

Airflow Version Airflow: 3.3.2 Python: 3.12.13 OS: RHEL 9 (x86_64) Executor: LocalExecutor Metadata DB: PostgreSQL OpenTelemetry enabled via Airflow configuration Azure Key Vault secrets backend enabled Description

After upgrading from Airflow 3.1.8 to 3.3.2, the environment became unusable when OpenTelemetry was enabled.

Two independent symptoms occur:

DAG Processor DAG files are discovered normally. DAG Processor starts parser children. Child processes never complete parsing. DAG File Processing Stats repeatedly show:

# DAGs = 0
# Errors = 0
Current Duration = increasing

until hitting:

dag_file_processor_timeout

and being killed.

After timeout:

# Errors = 1

is recorded.

No actual import errors are written to:

import_error

and:

serialized_dag

is not updated by the live DAG processor.

Manual serialization via:

airflow dags reserialize

works correctly.


LocalExecutor

Scheduler successfully moves tasks:

scheduled -> queued

Example scheduler log:

Trying to enqueue tasks ... for executor: LocalExecutor(parallelism=4)

However:

tasks remain permanently queued LocalExecutor workers never appear tasks never transition to running


Key Observation

Disabling OpenTelemetry entirely immediately resolves both issues.

When OTEL is enabled DAG Processor parser children hang LocalExecutor workers never start Tasks remain queued indefinitely

When OTEL is disabled DAG Processor functions normally serialized_dag updates LocalExecutor workers start queued tasks execute normally

This behavior is fully reproducible.

py-spy Evidence DAG Processor child

Repeatedly captured in:

submit
get_aggregated_resources
_get_process_dependent_resource
_handle_fork
_after_in_child

Example stack:

submit (concurrent/futures/thread.py)
get_aggregated_resources (resources/__init__.py)
_get_process_dependent_resource (resources/__init__.py)
_handle_fork (trace/__init__.py)
_after_in_child (trace/__init__.py)

Scheduler LocalExecutor worker creation

Captured while trying to spawn LocalExecutor workers:

_spawn_worker
_spawn_workers_with_gc_freeze
LocalExecutor.start
multiprocessing.Process.start
_launch
_after_in_child
_handle_fork

Example:

_spawn_worker (airflow/executors/local_executor.py)
_spawn_workers_with_gc_freeze (airflow/executors/local_executor.py)
start (airflow/executors/local_executor.py)
_launch (multiprocessing/popen_fork.py)
_after_in_child (trace/__init__.py)
_handle_fork (trace/__init__.py)

The LocalExecutor worker never completes startup.


Additional Findings

Works Metadata DB connectivity Scheduler heartbeat Triggerer heartbeat API Server Azure Key Vault secret resolution Manual DAG import Manual DAG serialization

Does not work DAG Processor parser child completion LocalExecutor worker startup

OpenTelemetry Versions opentelemetry-api==1.44.0 opentelemetry-sdk==1.44.0 opentelemetry-exporter-otlp==1.44.0 opentelemetry-exporter-otlp-proto-grpc==1.44.0 opentelemetry-exporter-otlp-proto-http==1.44.0 opentelemetry-semantic-conventions==0.65b0

Installed via official Airflow 3.3.2 constraints.


Comparison with Airflow 3.1.8

On the same infrastructure:

Same OS Same Python major version Same PostgreSQL Same Key Vault integration

Airflow 3.1.8 works correctly.

Notably, LocalExecutor worker processes are created normally in 3.1.8, while they never appear in 3.3.2 when OpenTelemetry is enabled.


Questions Is this a known issue with Airflow 3.3.2 + OpenTelemetry? Are there recommended OpenTelemetry settings for Airflow 3.3.x when using LocalExecutor?

*Copilot help taken to format as part of the debugging session

What you think should happen instead?

DAG Processor, Scheduler like components should startup and operate normally

Operating System

RHEL 9.x

Deployment

Virtualenv installation

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

Not Applicable

Kubernetes Version

No response

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

No response

Are you willing to submit PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

zoomingrocket avatar Sep 22 '26 23:09 zoomingrocket

Hi @potiuk , I’d be interested in working on this issue. If it’s still available, could you please confirm that I can take it up? I’ll investigate the worker hook construction, add the regression test for the inherited connection overrides, and raise a PR.

Thanks!

kadubhumika avatar Sep 23 '26 10:09 kadubhumika

I’d like to work on this and submit a PR.

Diagnosis

The py-spy dump points to a post-fork deadlock: OpenTelemetry's _after_in_child fork hook (TracerProvider._handle_fork) calls _get_process_dependent_resource(), which spins up a concurrent.futures.ThreadPoolExecutor inside an at_fork handler while inheriting locked/corrupted threading state from the multi-threaded parent process. Furthermore, forked children inherit dead BatchSpanProcessor daemon threads, causing subsequent force_flush calls to stall.

Proposed Fix

  1. Patch TracerProvider._handle_fork: Neutralize TracerProvider._handle_fork in airflow_shared.observability.traces to prevent it from invoking resource detection tasks on a ThreadPoolExecutor inside the fork hook.
  2. Post-Fork Reset: Register an os.register_at_fork(after_in_child=...) hook (mirroring metrics.stats) to reset trace._TRACER_PROVIDER to a no-op proxy provider in forked children, eliminating dead daemon threads and flush stalls.
  3. Verification: Add tests verifying that LocalExecutor workers and DAG processor children start and complete cleanly when OpenTelemetry is enabled.

schizophrenicmaniac avatar Sep 23 '26 15:09 schizophrenicmaniac

Hi @potiuk , I had commented earlier that I’d like to work on this issue. I saw that @schizophrenicmaniac has also started working on it this. I just wanted to mention that I had expressed interest earlier as well. Could you please let me know how we should proceed? Thanks!

kadubhumika avatar Sep 23 '26 17:09 kadubhumika

@schizophrenicmaniac - One interesting observation is with pyPI virtual env install of v3.3.2, the site-packages/airflow/observability folder has no "traces" folder itself, do we have a packaging issue as part of move https://github.com/apache/airflow/pull/56187 ? This is the directory "observability" structure with 3.3.2 virtual environment installed with constraint file

[..observability]$ tree . ├── init.py ├── metrics │   ├── datadog_logger.py │   ├── init.py │   ├── otel_logger.py │   ├── pycache │   │   ├── datadog_logger.cpython-312.pyc │   │   ├── init.cpython-312.pyc │   │   ├── otel_logger.cpython-312.pyc │   │   ├── statsd_logger.cpython-312.pyc │   │   └── stats_utils.cpython-312.pyc │   ├── statsd_logger.py │   └── stats_utils.py ├── pycache │   ├── init.cpython-312.pyc │   └── stats.cpython-312.pyc └── stats.py

zoomingrocket avatar Sep 23 '26 20:09 zoomingrocket

@zoomingrocket Thanks for checking! The missing traces folder in airflow/observability/ is actually expected and not a packaging issue. PR #63566 intentionally moved the tracing helpers out to a shared distribution, so it's now located at site-packages/airflow_shared/observability/traces instead.

The trace/__init__.py seen in the stack trace of the hanging processes belongs to the opentelemetry.sdk library, not Airflow. The hang is caused by an OpenTelemetry deadlock where its TracerProvider tries to acquire inherited locks during os.fork(). This PR safely bypasses that OpenTelemetry lock issue by overriding the fork handler.

schizophrenicmaniac avatar Sep 25 '26 07:09 schizophrenicmaniac

@schizophrenicmaniac - Thanks for the clarification. I was able to validate by replacing the committed init.py and able to now start DAG processor, scheduler properly with OTEL being ON and transmitted! It will be great if a unit test is added so that OTEL stability is validated before final builds :) Thank you again; hope to see this merged soon!

zoomingrocket avatar Oct 01 '26 22:10 zoomingrocket

@kadubhumika @schizophrenicmaniac - Seems like our original fix though working is not ideal, look at the comment: https://github.com/apache/airflow/pull/73626#issuecomment-6647016724 and see if you want to revise your fix! Thanks in advance

zoomingrocket avatar Nov 16 '26 21:11 zoomingrocket

The issue seem to came up with Airflow 3.3.1, see #71772. 3.3.0 still works in our environment

n-badtke-cg avatar Nov 24 '26 13:11 n-badtke-cg

According to https://github.com/apache/airflow/pull/73626 and our own testings: It seems that:

  • only opentelemetry tracing/traces exports are affected
  • logs and metrics are still functional.

n-badtke-cg avatar Nov 24 '26 14:11 n-badtke-cg

Not only LocalExecutor, but also CeleryExecutor

n-badtke-cg avatar Nov 24 '26 16:11 n-badtke-cg