Skip to content

Bug: Temp file leak when script instrumentation write fails #196

@YUVRAJ-SINGH-3178

Description

@YUVRAJ-SINGH-3178
  • Summary: Instrumentation creates a temp file via tempfile.mkstemp() and sets run_path to it after a successful write. If the write fails, the code falls back to the original full_path but the created temp file can be left orphaned on disk.
  • Location: app.py (script instrumentation / run path handling).
  • Steps to reproduce:
    1. Trigger a script run that causes instrumentation (the /api/scripts/run flow).
    2. Simulate a write failure (e.g., make the script directory unwritable or fill the disk).
    3. Observe a .tmp_run_*.sh temp file remains after the error.
  • Expected: Any temp file created during instrumentation is always removed, even if writing fails.
  • Actual: Created temp file can persist when the write fails and run_path is reset to full_path.
  • Suggested fix: Track the created temp path separately (e.g., temp_path_created) and always attempt to unlink it in cleanup/finally (or use NamedTemporaryFile(delete=True) / context manager).

@siddu-k Assign me this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions