Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_hooks: ensure event after been emitted on runInAsyncScope #31784

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/async_hooks.js
Expand Up @@ -22,6 +22,7 @@ const {
executionAsyncId,
triggerAsyncId,
// Private API
hasAsyncIdStack,
getHookArrays,
enableHooks,
disableHooks,
Expand Down Expand Up @@ -179,12 +180,16 @@ class AsyncResource {
const asyncId = this[async_id_symbol];
emitBefore(asyncId, this[trigger_async_id_symbol], this);

const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);
try {
const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);

emitAfter(asyncId);
return ret;
return ret;
} finally {
if (hasAsyncIdStack())
emitAfter(asyncId);
}
}

emitDestroy() {
Expand Down
@@ -0,0 +1,9 @@
'use strict';

require('../common');
const { AsyncResource } = require('async_hooks');

try {
new AsyncResource('foo').runInAsyncScope(() => { throw new Error('bar'); });
} catch {}
// Should abort (fail the case) if async id is not matching.

This file was deleted.