Repository navigation
fs: do not swallow exceptions thrown by completion callbacks - #66308
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66308 +/- ##
==========================================
+ Coverage 90.59% 90.67% +0.07%
==========================================
Files 797 797
Lines 278230 278235 +5
Branches 53482 53499 +17
==========================================
+ Hits 252066 252284 +218
+ Misses 16558 16334 -224
- Partials 9606 9617 +11
🚀 New features to boost your workflow:
|
57b5139 to
84f74ce
Compare
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>
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
b107688 to
4e3d6b8
Compare
|
Landed in c9f1d2d |
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: #65667 Refs: #57706 Signed-off-by: marcopiraccini <marco.piraccini@gmail.com> PR-URL: #66308 Reviewed-By: Paolo Insogna <paolo@cowtech.it>
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: #65667 Refs: #57706 Signed-off-by: marcopiraccini <marco.piraccini@gmail.com> PR-URL: #66308 Reviewed-By: Paolo Insogna <paolo@cowtech.it>
|
Thanks for the fix. I'd like to ask whether this could be backported to v24.x. The latest v24 release (v24.22.3) still aborts on a minimal import test from 'node:test';
import { mkdtemp, rm } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { createServer } from 'node:http';
test('unhandled listen error inside an async fs wrapper', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'repro-'));
try {
const server = createServer(); // no 'error' listener
await new Promise((resolve) => server.listen(0, '192.0.2.1', resolve)); // EADDRNOTAVAIL
} finally {
await rm(root, { recursive: true, force: true });
}
});
I don't see a v24.x backport or a backport label on this PR. In practice, one failed (Found, reduced and verified with the help of an AI coding assistant.) |
|
@Aragorn2046 prepared the PR for the backport: #67703 |
|
@ShogunPanda the v24.x backport is open as #67703: the cherry-pick conflicted only on main-only code (the Could you add |
Since #57706 the completion callbacks of
fs.mkdtemp,fs.realpath.native,fs.readlink,fs.mkdir({ recursive }),fs.readdir({ recursive })anddir.read()call into JS while theTryCatchmeant forStringBytes::Encodeis still in scope.Any exception thrown by the user callback, or by the
nextTickqueue drained right after it (e.g. afterawait fsp.mkdtemp()), is swallowed: the process prints nothing and exits 0, anduncaughtExceptionnever fires. v22 is not affected.This moves the
TryCatchinto a small helper that produces the value first and callsResolve()/Reject()only after leaving it.Fixes: #65667