fs: use correct position when retrying writev - #66203
Open
christianaurichzm wants to merge 1 commit into
Open
christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
writevAll() tracks the position for the next attempt in its `pos` argument, but calls fs.writev() with `this.pos`. WriteStream._writev() advances `this.pos` by the whole batch right after starting the write, so a retry from the asynchronous callback resumes at the end of the batch instead of after the bytes that reached the file. A partial write leaves a hole and puts the remainder past its place; an EAGAIN retry moves forward even though nothing was written. Use the local `pos`, as writeAll() already does. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66203 +/- ##
=======================================
Coverage 90.29% 90.29%
=======================================
Files 790 790
Lines 272529 272529
Branches 52031 52033 +2
=======================================
+ Hits 246083 246089 +6
+ Misses 16909 16897 -12
- Partials 9537 9543 +6
🚀 New features to boost your workflow:
|
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.
WriteStreamretries a partialwritev()at the wrong position whenstartis set.writevAll()tracks the next position inpos, but passesthis.postowritev()._writev()advancesthis.posby the full batch size before the callback runs, so a short write can retry from the end of the batch instead of after the bytes that were written.For a 12-byte batch starting at 0, with the first call writing 3 bytes:
The second call should be at 3. The current result is:
EAGAINhas the same problem: the retry uses the advancedthis.poseven though no bytes were written.Pass
posinstead, matchingwriteAll().The regression test covers partial writes at
start: 0andstart: 5,EAGAIN, and the unpositioned case.For
start: 5:make lintpasses.parallelandsequentialwere also run on Linux x64. Fourparallelfailures related to--use-openssl-caalso reproduce on the base commit.Refs: #49211