Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 700f766

Browse filesBrowse files
apapirovskiBethGriggs
authored andcommitted
process: ignore asyncId 0 in exception handler
Today, the global uncaught exception handler is the only place where asyncId 0 is not ignored and we still proceed to call emitAfter. This would've already failed one of our correctness tests in async_hooks if not for some other code meant to handle a different edge case. Fixes: #22982 PR-URL: #41424 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8681c83 commit 700f766
Copy full SHA for 700f766

File tree

Expand file treeCollapse file tree

3 files changed

+24
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/process/execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/execution.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const {
2020
clearAsyncIdStack,
2121
hasAsyncIdStack,
2222
afterHooksExist,
23-
emitAfter
23+
emitAfter,
24+
popAsyncContext,
2425
} = require('internal/async_hooks');
2526

2627
// shouldAbortOnUncaughtToggle is a typed array for faster
@@ -183,7 +184,11 @@ function createOnGlobalUncaughtException() {
183184
// Emit the after() hooks now that the exception has been handled.
184185
if (afterHooksExist()) {
185186
do {
186-
emitAfter(executionAsyncId());
187+
const asyncId = executionAsyncId();
188+
if (asyncId === 0)
189+
popAsyncContext(0);
190+
else
191+
emitAfter(asyncId);
187192
} while (hasAsyncIdStack());
188193
}
189194
// And completely empty the id stack, including anything that may be
Collapse file

‎test/async-hooks/init-hooks.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/init-hooks.js
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ class ActivityCollector {
168168
}
169169
const err = new Error(`Found a handle whose ${hook}` +
170170
' hook was invoked but not its init hook');
171-
// Don't throw if we see invocations due to an assertion in a test
172-
// failing since we want to list the assertion failure instead
173-
if (/process\._fatalException/.test(err.stack)) return null;
174171
throw err;
175172
}
176173
return h;
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const initHooks = require('./init-hooks');
5+
6+
const hooks = initHooks();
7+
hooks.enable();
8+
9+
setImmediate(() => {
10+
throw new Error();
11+
});
12+
13+
setTimeout(() => {
14+
throw new Error();
15+
}, 1);
16+
17+
process.on('uncaughtException', common.mustCall(2));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.