Skip to content

fs: preserve readFile() errors for numeric file descriptors#64368

Open
jibin7jose wants to merge 1 commit into
nodejs:mainfrom
jibin7jose:fix-fs-readfile-buffer-fd-error
Open

fs: preserve readFile() errors for numeric file descriptors#64368
jibin7jose wants to merge 1 commit into
nodejs:mainfrom
jibin7jose:fix-fs-readfile-buffer-fd-error

Conversation

@jibin7jose

@jibin7jose jibin7jose commented Jul 8, 2026

Copy link
Copy Markdown

Summary

fs.readFile() with a numeric file descriptor and the new buffer option could lose errors on the user-fd path.

Root cause

In lib/internal/fs/read/context.js, ReadFileContext.close(err) did not forward err when isUserFd was true. As a result, failures that should have reached the callback, including an undersized caller-provided buffer, could be treated as successful completion.

Fix

Forward the close error for user-supplied file descriptors so the final callback receives the actual failure instead of silently succeeding.

Tests

Add regression coverage for the numeric file descriptor path with:

  • a preallocated buffer
  • a function-returned buffer
  • a buffer that is too small

This verifies the error is preserved for the callback-based API.

Fixes: #64367

@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 Jul 8, 2026
@jibin7jose jibin7jose changed the title fs: preserve readFile() errors for numeric fds fs: preserve readFile() errors for numeric file descriptors Jul 8, 2026
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.

fs: preserve readFile() errors when using a numeric fd and buffer option

2 participants