fix(processing): close temp file handle before deletion on Windows#5921
Open
nileshpatil6 wants to merge 1 commit into
Open
fix(processing): close temp file handle before deletion on Windows#5921nileshpatil6 wants to merge 1 commit into
nileshpatil6 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5873
On Windows,
FrameworkProcessor._package_coderaisedPermissionError: [WinError 32]when packaging a localsource_dir. The root cause:os.unlink(tmp.name)was called inside theNamedTemporaryFilewithblock 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:
tmp.nametotmp_pathbefore thewithblock closesos.unlink(tmp_path)outside thewithblock so the handle is fully closed before deletionopen(tmp_path, "rb").read()with awithstatement to avoid leaking the read handleos.unlinkin atry/except OSErrorfor best-effort cleanupThe fix is a no-op on Linux/macOS.