Skip to content

Commit b3295b8

Browse files
islandryutargos
authored andcommitted
process: fix wrong asyncContext under unhandled-rejections=strict
Fixes: #60034 PR-URL: #60103 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
1 parent 5538cfc commit b3295b8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/internal/process/promises.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function strictUnhandledRejectionsMode(promise, promiseInfo, promiseAsyncId) {
343343
reason : new UnhandledPromiseRejection(reason);
344344
// This destroys the async stack, don't clear it after
345345
triggerUncaughtException(err, true /* fromPromise */);
346-
if (promiseAsyncId === undefined) {
346+
if (promiseAsyncId !== undefined) {
347347
pushAsyncContext(
348348
promise[kAsyncIdSymbol],
349349
promise[kTriggerAsyncIdSymbol],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Flags: --unhandled-rejections=strict
2+
'use strict';
3+
4+
const common = require('../common');
5+
const fs = require('fs');
6+
const assert = require('assert');
7+
8+
process.on('unhandledRejection', common.mustNotCall);
9+
10+
process.on('uncaughtException', common.mustCall((err) => {
11+
assert.ok(err.message.includes('foo'));
12+
}));
13+
14+
15+
async function readFile() {
16+
return fs.promises.readFile(__filename);
17+
}
18+
19+
async function crash() {
20+
throw new Error('foo');
21+
}
22+
23+
24+
async function main() {
25+
crash();
26+
readFile();
27+
}
28+
29+
main();

0 commit comments

Comments
 (0)