Skip to content

fix(processing): close temp file handle before deletion on Windows#5921

Open
nileshpatil6 wants to merge 1 commit into
aws:masterfrom
nileshpatil6:fix/windows-tempfile-permission-error
Open

fix(processing): close temp file handle before deletion on Windows#5921
nileshpatil6 wants to merge 1 commit into
aws:masterfrom
nileshpatil6:fix/windows-tempfile-permission-error

Conversation

@nileshpatil6
Copy link
Copy Markdown

Fixes #5873

On Windows, FrameworkProcessor._package_code raised PermissionError: [WinError 32] when packaging a local source_dir. The root cause: os.unlink(tmp.name) was called inside the NamedTemporaryFile with block while the file handle was still open. Windows does not allow deleting a file with any open handle; Linux/macOS do, which is why the bug is Windows-only.

Changes:

  • Save tmp.name to tmp_path before the with block closes
  • Move os.unlink(tmp_path) outside the with block so the handle is fully closed before deletion
  • Replace the bare open(tmp_path, "rb").read() with a with statement to avoid leaking the read handle
  • Wrap os.unlink in a try/except OSError for best-effort cleanup

The fix is a no-op on Linux/macOS.

FrameworkProcessor._package_code called os.unlink(tmp.name) inside the
NamedTemporaryFile with block, while the file handle was still open. On
Windows this raises PermissionError (WinError 32) because files cannot
be deleted while any handle is open. On Linux/macOS the pattern works
but leaks a file handle via the bare open() call.

Move os.unlink outside the with block so the handle is closed first,
and use a proper with-statement for the S3 upload read.

Fixes aws#5873

Signed-off-by: nileshpatil6 <technil6436@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FrameworkProcessor._package_code fails on Windows with PermissionError (WinError 32) when deleting temp tar.gz

1 participant