| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 93b1bb8 commit 4458378
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ const { | |||
| 17 | 17 | executionAsyncId, | |
| 18 | 18 | triggerAsyncId, | |
| 19 | 19 | // Private API | |
| 20 | + hasAsyncIdStack, | ||
| 20 | 21 | getHookArrays, | |
| 21 | 22 | enableHooks, | |
| 22 | 23 | disableHooks, | |
@@ -172,7 +173,8 @@ class AsyncResource { | |||
| 172 | 173 | return fn(...args); | |
| 173 | 174 | return Reflect.apply(fn, thisArg, args); | |
| 174 | 175 | } finally { | |
| 175 | - emitAfter(asyncId); | ||
| 176 | + if (hasAsyncIdStack()) | ||
| 177 | + emitAfter(asyncId); | ||
| 176 | 178 | } | |
| 177 | 179 | } | |
| 178 | 180 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const async_hooks = require('async_hooks'); | ||
| 5 | + | ||
| 6 | + // Regression test for https://github.com/nodejs/node/issues/30080: | ||
| 7 | + // An uncaught exception inside a queueMicrotask callback should not lead | ||
| 8 | + // to multiple after() calls for it. | ||
| 9 | + | ||
| 10 | + let µtaskId; | ||
| 11 | + const events = []; | ||
| 12 | + | ||
| 13 | + async_hooks.createHook({ | ||
| 14 | + init(id, type, triggerId, resoure) { | ||
| 15 | + if (type === 'Microtask') { | ||
| 16 | + µtaskId = id; | ||
| 17 | + events.push('init'); | ||
| 18 | + } | ||
| 19 | + }, | ||
| 20 | + before(id) { | ||
| 21 | + if (id === µtaskId) events.push('before'); | ||
| 22 | + }, | ||
| 23 | + after(id) { | ||
| 24 | + if (id === µtaskId) events.push('after'); | ||
| 25 | + }, | ||
| 26 | + destroy(id) { | ||
| 27 | + if (id === µtaskId) events.push('destroy'); | ||
| 28 | + } | ||
| 29 | + }).enable(); | ||
| 30 | + | ||
| 31 | + queueMicrotask(() => { throw new Error(); }); | ||
| 32 | + | ||
| 33 | + process.on('uncaughtException', common.mustCall()); | ||
| 34 | + process.on('exit', () => { | ||
| 35 | + assert.deepStrictEqual(events, ['init', 'after', 'before', 'destroy']); | ||
| 36 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments