async_hooks: a promiseResolve hook that calls a native binding turns a caught ESM evaluation error into a fatal exit
Version
v25.7.0 (also v22.22 and v24.14, per the report that led here)
Platform
Darwin arm64, macOS
Subsystem
async_hooks
What steps will reproduce the bug?
An async_hooks hook whose promiseResolve callback calls a native binding (here performance.now()) turns a module evaluation error that is caught by the caller into an uncaught fatal error, and the process exits with code 1.
// repro.mjs
import { createHook } from "node:async_hooks";
createHook({ promiseResolve() { performance.now(); } }).enable();
try {
await import("data:text/javascript,throw new Error('x')");
} catch {
console.log("caught");
}
How often does it reproduce? Is there a required condition?
Always, given a promiseResolve hook that calls into a native binding. Both conditions matter:
- The hook body must do a native call. An empty
promiseResolve() {}is fine (exit 0).process.hrtime.bigint()reproduces as well asperformance.now(). - The throwing module does not have to be a
data:URL. A plain file that throws at the top level (await import("./bad.mjs")) reproduces the same way.
What is the expected behavior?
The rejection is handled: caught is printed and the process exits 0.
What do you see instead?
Error: x
at data:text/javascript,throw new Error('x'):1:7
at ModuleJob.run (node:internal/modules/esm/module_job:430:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:639:26)
at async file:///private/tmp/repro.mjs:4:3
Exit code 1, caught never printed. The same script with Date.now() instead of performance.now() prints caught and exits 0, so this is not the missing try/catch.
From a debugger the exit comes from fatalError in node:internal/async_hooks: the error of the failed module evaluation is reported through emitHook as if it had escaped, and fatalError calls process.exit(1). uncaughtException and unhandledRejection handlers, and process.exit being overridden, do not see it.
Why it matters in practice
This was found through a dev server that registers a promiseResolve hook calling performance.now() (React's development RSC renderer). Loading one extension whose bundle throws during native ESM import — while the loader would have recovered by retrying with a transpiling fallback — kills a long-running process that has already handled thousands of requests, instead of rejecting a promise the caller catches. Any library that instruments promises inherits the same fragility.
Additional information
Minimal probes:
| hook body | outcome |
|---|---|
performance.now() |
exit 1 |
process.hrtime.bigint() |
exit 1 |
Date.now() |
caught, exit 0 |
| empty | caught, exit 0 |
Reproduced on Linux with v22.20.0, v24.22.3 and v25.6.1. A few things that narrow it down:
- It isn't specific to fast API calls.
os.hostname()andprocess.memoryUsage()in the hook reproduce it too, and so doesperformance.now()with--no-turbo-fast-api-calls. - The error is thrown by the native call itself. With a
try/catcharound the call inside the hook, the catch block receives the module's error (x), and then theimport()rejection is caught normally and the process exits 0. So the hook runs while the module's exception is still pending, and the first API call made from the hook throws it. - Only a module that throws synchronously triggers it. With top-level
awaitbefore thethrow(or a module that containsawaitbut throws first), the rejection is caught and nothing escapes. - It doesn't go through the ESM loader: evaluating
new vm.SourceTextModule("throw new Error('x')")with--experimental-vm-modulesshows the same behavior.
A build of main from early November (V8 15.6) doesn't reproduce any of these cases, including the vm.SourceTextModule one, so it looks fixed upstream, most likely by the V8 update. I haven't checked v26 or v27.