Skip to content

fs: avoid unhandled rejection in filehandle readableWebStream close#62053

Open
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02:fix/56116-filehandle-readablewebstream-sometim
Open

fs: avoid unhandled rejection in filehandle readableWebStream close#62053
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02:fix/56116-filehandle-readablewebstream-sometim

Conversation

@jorgitin02
Copy link

Fixes: #56116

When FileHandle emits 'close', readableWebStream currently calls readableStreamCancel(readable) without handling rejection. If the stream has already errored (for example after EBADF), this can surface as an unhandled rejection.

This change consumes that cancel rejection on the close-notify path.

Tests:

  • add regression for errored readableWebStream + explicit file.close() (no unhandled rejection)
  • add BYOB variant for the same edge path
  • keep a success-path safety check

Signed-off-by: jorge guerrero <grrr.jrg@gmail.com>
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Mar 1, 2026
@jorgitin02
Copy link
Author

CC @nodejs/fs @nodejs/streams

This PR targets #56116.

What it changes:

  • Handles the readableStreamCancel(readable) rejection on FileHandle 'close' notification path.
  • Prevents unhandled rejection when the stream is already errored (e.g. EBADF) and close-notify triggers cancel.

Why:

  • readableWebStream() could surface an unhandled rejection in this edge sequence:
  1. stream read errors
  2. FileHandle emits 'close'
  3. close handler calls readableStreamCancel(readable) without consuming rejection

Tests added:

  • Regression: errored readableWebStream() + explicit file.close() does not crash due to unhandled rejection.
  • Edge: same path with BYOB reader.
  • Safety: successful read/close path remains unaffected.

Validation run:

  • ./node test/parallel/test-filehandle-readablestream-error-close.js
  • ./node test/parallel/test-filehandle-readablestream.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fileHandle.readableWebStream sometimes crashes on large inputs

2 participants