Conversation
FanWu-ai
marked this pull request as ready for review
October 5, 2026 04:56
This branch has not been deployed
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.
Summary
Clean up the temporary file when
rewrite()fails while closing its buffered output. The cleanup scope now includes the temporary-file context manager's exit, while preserving the original target and propagating the error.A write can be buffered successfully and fail only during close (for example, when the filesystem reports a size limit). Previously, that exception escaped before
_discard_temp_file(), leaving a partial.tmp_*file behind afterset_key()orunset_key().Changes
KeyboardInterrupt.Reproduction and related work
An isolated Linux subprocess with
RLIMIT_FSIZE=3andSIGXFSZignored reproduces a real close-timeEFBIGwithout mocking file I/O. Creating a new file, updating an existing file, and removing a key each leave one partial temporary file on the base; this patch leaves none. The original target remains unchanged in all cases.This extends the cleanup introduced in #686. It also covers a failure boundary still present with the flush/fsync change proposed in #717: a repeated buffered-write failure during context exit can escape its inner cleanup scope.
Validation
Against main at
0b2880591780a426b0551436f47a17e7a76d954f:Windows, PyPy, Python 3.11, and free-threaded runtime coverage are left to upstream CI; the local runtime results above are Linux only.
AI assistance: this patch, tests, and description were prepared and checked with OpenAI Codex. Submitted as a draft for human review.