Skip to content

Trace the dag-processor job instead of its parent process with memray - #72367

Merged
potiuk merged 1 commit into
apache:mainfrom
Eason09053360:fix-dag-processor-memray-wrong-process
Sep 7, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
Eason09053360:fix-dag-processor-memray-wrong-process

Conversation

@Eason09053360

Copy link
Copy Markdown
Contributor

@enable_memray_trace was on the dag-processor's outer CLI function. Both paths
that function takes — run_command_with_daemon_option and, under --dev,
run_with_reloader — fork before the job runs, and memray.Tracker defaults to
follow_fork=False. So the tracer stayed with the parent while every allocation
worth measuring happened in the child, and an opted-in user got a capture file
containing interpreter startup instead of the profile they asked for.
It fails silently: the file looks perfectly normal.

The three sibling components already decorate their inner run function —
_run_scheduler_job, triggerer_run, _run_api_server. This makes
dag-processor match them by extracting _run_dag_processor_job and moving the
decorator onto it.

set_component_mp_start_method() and _create_dag_processor_job_runner()
deliberately stay in the parent. The latter calls validate_dag_bundle_arg,
which raises SystemExit on an unknown --bundle-name; moving it past the fork
would bury that error in a daemonized child where the user never sees it.

No behaviour change for anyone who has not opted in — [profiling] memray_trace_components is unset by default.

The regression test asserts the invariant behaviourally rather than structurally:
no memray.Tracker may be constructed while the CLI function runs, and exactly
one must be constructed when the callback that lands on the far side of the fork
is invoked. Verified failing against the unfixed code both whole-file and in isolation.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

The tracer was attached to the CLI entry point, which forks before the job
runs and does not follow the child, so anyone who opted into profiling got a
capture of interpreter startup rather than of the work they enabled it to
investigate. Dag-processor memory growth is exactly what this feature exists
to diagnose, and it was the one component of the four that reported on the
wrong process.
@potiuk potiuk added this to the Airflow 3.3.2 milestone Sep 7, 2026
@potiuk
potiuk merged commit 4c32caa into apache:main Sep 7, 2026
73 checks passed
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

vatsrahul1001 added a commit that referenced this pull request Sep 8, 2026
… with memray (#72367) (#72661)

The tracer was attached to the CLI entry point, which forks before the job
runs and does not follow the child, so anyone who opted into profiling got a
capture of interpreter startup rather than of the work they enabled it to
investigate. Dag-processor memory growth is exactly what this feature exists
to diagnose, and it was the one component of the four that reported on the
wrong process.
(cherry picked from commit 4c32caa)

Co-authored-by: Y-C <[email protected]>
Co-authored-by: Eason09053360 <[email protected]>
Co-authored-by: Rahul Vats <[email protected]>
regarmukesh3g pushed a commit to regarmukesh3g/airflow that referenced this pull request Sep 27, 2026
…apache#72367)

The tracer was attached to the CLI entry point, which forks before the job
runs and does not follow the child, so anyone who opted into profiling got a
capture of interpreter startup rather than of the work they enabled it to
investigate. Dag-processor memory growth is exactly what this feature exists
to diagnose, and it was the one component of the four that reported on the
wrong process.

Co-authored-by: Eason09053360 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants