Skip to content

fs: use correct position when retrying writev - #66203

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:fs-writev-retry-position
Nov 15, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:fs-writev-retry-position

Conversation

@christianaurichzm

Copy link
Copy Markdown
Member

WriteStream retries a partial writev() at the wrong position when start is set.

writevAll() tracks the next position in pos, but passes this.pos to writev(). _writev() advances this.pos by 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:

writev at 0
writev at 12

The second call should be at 3. The current result is:

"AAA\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ABBBBCCCC"

EAGAIN has the same problem: the retry uses the advanced this.pos even though no bytes were written.

Pass pos instead, matching writeAll().

The regression test covers partial writes at start: 0 and start: 5, EAGAIN, and the unpositioned case.

For start: 5:

partial write: [5, 17] -> [5, 8]
EAGAIN:        [5, 17] -> [5, 5]

make lint passes. parallel and sequential were also run on Linux x64. Four parallel failures related to --use-openssl-ca also reproduce on the base commit.

Refs: #49211

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>
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Sep 22, 2026
@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (36dd044) to head (f6535a4).
⚠️ Report is 907 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/internal/fs/streams.js 94.45% <100.00%> (+1.34%) ⬆️

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@christianaurichzm

Copy link
Copy Markdown
Member Author

@atlowChemi since you finished writevAll() in #49211, could you take a look at this one-line fix when you get a chance? cc @lpinca. If it looks good, could you also add request-ci? Thanks!

@christianaurichzm

Copy link
Copy Markdown
Member Author

@ronag, since writevAll() comes from your feb5b0f, could you take a look at this when you get a chance? It passes this.pos instead of the local pos, so a short writev() is retried past the bytes that were actually written. cc @panva. If it looks good, could you also add request-ci? Thanks!

@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 13, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm christianaurichzm removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 14, 2026
@ronag ronag added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 14, 2026
@ronag
ronag requested a review from mcollina November 14, 2026 20:18

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@github-actions github-actions Bot added request-ci-failed Starting CI with the request-ci label failed and requires manual intervention. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Failed to start CI

   ℹ  Existing CI run found: https://ci.nodejs.org/job/node-test-pull-request/79082/
   ✖  Refusing to start a potentially duplicate CI job. The existing CI run is still in progress.
Full Auto Start CI output
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66203
�[36m⠋�[39m Getting commits from nodejs/node/pull/66203
�[36m⠙�[39m Validating Jenkins credentials
�[36m⠙�[39m Validating Jenkins credentials
✔  Jenkins credentials valid
�[36m⠹�[39m Getting comments from nodejs/node/pull/66203
�[36m⠸�[39m Querying data for job/node-test-pull-request/79082/
�[36m⠸�[39m Querying data for job/node-test-pull-request/79082/
�[36m⠸�[39m Querying API for job/node-test-pull-request/79082/
✔  Build data downloaded
   ℹ  Existing CI run found: https://ci.nodejs.org/job/node-test-pull-request/79082/
   ✖  Refusing to start a potentially duplicate CI job. The existing CI run is still in progress.

View workflow run

@christianaurichzm christianaurichzm added resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. and removed request-ci-failed Starting CI with the request-ci label failed and requires manual intervention. resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels Nov 14, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 14, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm christianaurichzm added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 15, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 15, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm christianaurichzm added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 15, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 2e59a6d into nodejs:main Nov 15, 2026
96 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 2e59a6d

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants