Skip to content

fs: do not swallow exceptions thrown by completion callbacks - #66308

Open
marcopiraccini wants to merge 1 commit into
nodejs:mainfrom
marcopiraccini:fs-trycatch-scope
Open

marcopiraccini wants to merge 1 commit into
nodejs:mainfrom
marcopiraccini:fs-trycatch-scope

Conversation

@marcopiraccini

@marcopiraccini marcopiraccini commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Since #57706 the completion callbacks of fs.mkdtemp, fs.realpath.native, fs.readlink, fs.mkdir({ recursive }), fs.readdir({ recursive }) and dir.read() call into JS while the TryCatch meant for StringBytes::Encode is still in scope.
Any exception thrown by the user callback, or by the nextTick queue drained right after it (e.g. after await fsp.mkdtemp()), is swallowed: the process prints nothing and exits 0, and uncaughtException never fires. v22 is not affected.

This moves the TryCatch into a small helper that produces the value first and calls Resolve()/Reject() only after leaving it.

Fixes: #65667

NOTE: make lint-js currently fails until #66307 lands

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Sep 26, 2026
@marcopiraccini
marcopiraccini marked this pull request as ready for review September 26, 2026 03:53
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.64516% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.39%. Comparing base (8812357) to head (57b5139).

Files with missing lines Patch % Lines
src/node_file-inl.h 60.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66308      +/-   ##
==========================================
+ Coverage   90.36%   90.39%   +0.02%     
==========================================
  Files         790      790              
  Lines      274292   274275      -17     
  Branches    52510    52491      -19     
==========================================
+ Hits       247874   247927      +53     
+ Misses      16901    16837      -64     
+ Partials     9517     9511       -6     
Files with missing lines Coverage Δ
src/node_dir.cc 71.61% <100.00%> (+0.82%) ⬆️
src/node_file.cc 75.44% <100.00%> (+0.22%) ⬆️
src/node_file-inl.h 83.59% <60.00%> (-1.47%) ⬇️

... and 29 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.

Since 93644d5 the TryCatch guarding StringBytes::Encode in the
completion callbacks of mkdtemp, realpath.native, readlink, recursive
mkdir, recursive readdir and dir.read is still active when the JS
callback runs. Exceptions thrown by the callback, or by the nextTick
queue drained after it, are caught by it and never reported.

Leave the TryCatch before calling into JS.

Fixes: nodejs#65667
Refs: nodejs#57706
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:test aborts in InternalCallbackScope::Close after listen EPERM

2 participants