Fix atomic file writes exposing empty destinations and leaking temp files - #9805
Merged
Conversation
The basename was cut with byteslice, which can split a multibyte character in half. Filesystems enforcing UTF-8 validity such as APFS then reject the temporary name with EILSEQ. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The temporary file was renamed into place before being closed, so buffered data had not reached the filesystem yet and a concurrent reader could observe an empty destination. A flush failure such as ENOSPC would surface only after the destination had already been replaced. Cleanup also moved to an ensure block, so an interrupt no longer leaks the temporary file. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
hsbt
force-pushed
the
atomic-file-writer-flush-cleanup
branch
from
August 25, 2026 02:04
eecd199 to
774bd08
Compare
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.
Gem::AtomicFileWriterrenamed the temporary file into place before closing it, so buffered data had not reached the filesystem yet. A concurrent reader could observe an empty destination, and a flush failure such asENOSPCwould surface only after the destination had already been replaced with a truncated file. Closing before the rename restores the ordering the writer had before it was refactored.The cleanup path had also become
rescue StandardError, so anInterruptfrom Ctrl-C skipped both the unlink and the rename and left.<name>.tmp.<hex>behind. It is back in anensureblock.Basename truncation used
byteslice, which can cut a multibyte character in half and make the temporary file name fail withEILSEQon filesystems that enforce UTF-8 validity such as APFS. It now trims at a character boundary.This file had a single test before. The invariants above are covered now.