GeezerVison is showing github.com — process: ignore asyncId 0 in exception handler · cspotcode/node@5178332
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/process/execution.js +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,8 @@ const { |
20 | 20 | clearAsyncIdStack, |
21 | 21 | hasAsyncIdStack, |
22 | 22 | afterHooksExist, |
23 | | - emitAfter |
| 23 | + emitAfter, |
| 24 | + popAsyncContext, |
24 | 25 | } = require('internal/async_hooks'); |
25 | 26 |
|
26 | 27 | // shouldAbortOnUncaughtToggle is a typed array for faster |
@@ -183,7 +184,11 @@ function createOnGlobalUncaughtException() { |
183 | 184 | // Emit the after() hooks now that the exception has been handled. |
184 | 185 | if (afterHooksExist()) { |
185 | 186 | do { |
186 | | - emitAfter(executionAsyncId()); |
| 187 | + const asyncId = executionAsyncId(); |
| 188 | + if (asyncId === 0) |
| 189 | + popAsyncContext(0); |
| 190 | + else |
| 191 | + emitAfter(asyncId); |
187 | 192 | } while (hasAsyncIdStack()); |
188 | 193 | } |
189 | 194 | // And completely empty the id stack, including anything that may be |
|
Collapse file
Copy file name to clipboardExpand all lines: test/async-hooks/init-hooks.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -168,9 +168,6 @@ class ActivityCollector { |
168 | 168 | } |
169 | 169 | const err = new Error(`Found a handle whose ${hook}` + |
170 | 170 | ' 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; |
174 | 171 | throw err; |
175 | 172 | } |
176 | 173 | return h; |
|
Collapse file
Copy file name to clipboard +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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)); |