Skip to content

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

Open
dheerajturaga wants to merge 1 commit intoapache:mainfrom
dheerajturaga:bugfix/tmp-file-leak
Open

Fix /tmp file leak when API server streams large task logs#66450
dheerajturaga wants to merge 1 commit intoapache:mainfrom
dheerajturaga:bugfix/tmp-file-leak

Conversation

@dheerajturaga
Copy link
Copy Markdown
Member

@dheerajturaga dheerajturaga commented May 5, 2026

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.
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.

1 participant