fs: honor flush option in writeFileSync utf8 fast path#63887
Open
MarshallOfSound wants to merge 1 commit into
Open
fs: honor flush option in writeFileSync utf8 fast path#63887MarshallOfSound wants to merge 1 commit into
MarshallOfSound wants to merge 1 commit into
Conversation
The C++ utf8 fast path added in 4466dee does not perform an fsync, but the gate routing writeFileSync through it did not consult the flush option added in e01c1d7. As a result writeFileSync(path, data, { encoding: 'utf8', flush: true }) wrote without flushing, while the same call without an explicit encoding flushed correctly. Skip the fast path when flush is requested. appendFileSync delegates to writeFileSync and was affected the same way. Extend the existing flush tests with the explicit-utf8-encoding case for both; the new cases fail without this change. Signed-off-by: Sam Attard <sattard@anthropic.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.
Description of Change
fs.writeFileSync(path, data, { encoding: 'utf8', flush: true })does not fsync. The C++ utf8 fast path (4466dee) skips the JS write loop that performs the flush, and its gate never checked theflushoption (e01c1d7, which predates it). The same call without an explicit encoding misses the fast path and flushes correctly. Verified with strace: zerofsyncsyscalls on the fast path, one on the slow path.This PR skips the fast path when
flush: trueis set, routing those writes through the existing open/write/fsync/close path.appendFileSyncdelegates towriteFileSyncand is fixed by the same change.Affects every release line since v21.3.0.
Extended the existing flush tests (
test-fs-write-file-flush.js,test-fs-append-file-flush.js) with the explicit-utf8-encoding case — the only combination that takes the fast path, and exactly the cell their matrices didn't cover. Both new cases fail without this change.Checklist
test/parallel/test-fs-*pass