Skip to content

Fix /tmp file leak when API server streams large task logs#66450

Merged
dheerajturaga merged 1 commit into
apache:mainfrom
dheerajturaga:bugfix/tmp-file-leak
May 10, 2026
Merged

Fix /tmp file leak when API server streams large task logs#66450
dheerajturaga merged 1 commit into
apache:mainfrom
dheerajturaga:bugfix/tmp-file-leak

Conversation

@dheerajturaga

@dheerajturaga dheerajturaga commented May 5, 2026

Copy link
Copy Markdown
Member

LogStreamAccumulator spills the in-flight log stream to a
NamedTemporaryFile(delete=False) in /tmp once a task's output exceeds
5000 lines. Cleanup was hooked only into the stream generator's
finally block, so the file leaked whenever the caller did not iterate
the generator to completion: client disconnect on the NDJSON streaming
endpoint, exception during list() materialisation on the JSON path, or
the caller using only total_lines and never accessing .stream.

A single production host accumulated ~39 GB of orphaned files from this
code path, with individual files up to 2.5 GB on tasks emitting
~10M log lines.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    ClaudeCode Opus 4.7

  LogStreamAccumulator spills the in-flight log stream to a
  NamedTemporaryFile(delete=False) in /tmp once a task's output exceeds
  5000 lines. Cleanup was hooked only into the stream generator's
  finally block, so the file leaked whenever the caller did not iterate
  the generator to completion: client disconnect on the NDJSON streaming
  endpoint, exception during list() materialisation on the JSON path, or
  the caller using only total_lines and never accessing .stream.

  A single production host accumulated ~39 GB of orphaned files from this
  code path, with individual files up to 2.5 GB on tasks emitting
  ~10M log lines.
@dheerajturaga dheerajturaga force-pushed the bugfix/tmp-file-leak branch from fe57e31 to f3c7317 Compare May 6, 2026 19:17
@dheerajturaga dheerajturaga merged commit 31d4837 into apache:main May 10, 2026
143 checks passed
@dheerajturaga dheerajturaga deleted the bugfix/tmp-file-leak branch May 10, 2026 03:04
@potiuk potiuk added this to the Airflow 3.2.2 milestone May 10, 2026
Comment thread airflow-core/src/airflow/utils/log/log_stream_accumulator.py
potiuk added a commit that referenced this pull request May 10, 2026
potiuk pushed a commit that referenced this pull request May 10, 2026
…66663)

Failure to remove the spill file is the exact failure mode that
caused the prior /tmp leak (~39 GB on a single host), so operators
need it visible in their logs rather than buried at debug level.

Follow-up to #66450.
github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request May 10, 2026
…s warnings (apache#66663)

Failure to remove the spill file is the exact failure mode that
caused the prior /tmp leak (~39 GB on a single host), so operators
need it visible in their logs rather than buried at debug level.

Follow-up to apache#66450.
(cherry picked from commit 1abd959)

Co-authored-by: Dheeraj Turaga <[email protected]>
potiuk pushed a commit that referenced this pull request May 10, 2026
…s warnings (#66663) (#66669)

Failure to remove the spill file is the exact failure mode that
caused the prior /tmp leak (~39 GB on a single host), so operators
need it visible in their logs rather than buried at debug level.

Follow-up to #66450.
(cherry picked from commit 1abd959)

Co-authored-by: Dheeraj Turaga <[email protected]>

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The three-layer cleanup is overkill in the best sense — guarantees cleanup regardless of caller behaviour, with each layer testable in isolation. The module-level _safe_remove to break the strong-ref cycle and the idempotent _cleanup are nicely subtle. One non-blocking suggestion inline on the OSError log level.


Drafted-by: Claude Opus 4.7 (1M context); reviewed by @potiuk before posting

jason810496 pushed a commit to jason810496/airflow that referenced this pull request May 11, 2026
vatsrahul1001 pushed a commit that referenced this pull request May 20, 2026
vatsrahul1001 pushed a commit that referenced this pull request May 20, 2026
…s warnings (#66663) (#66669)

Failure to remove the spill file is the exact failure mode that
caused the prior /tmp leak (~39 GB on a single host), so operators
need it visible in their logs rather than buried at debug level.

Follow-up to #66450.
(cherry picked from commit 1abd959)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants