Closed
Description
Consider the following code:
import { AsyncLocalStorage, createHook } from 'node:async_hooks';
import { notEqual } from 'assert/strict';
const hook = createHook({
init () {},
})
// Commenting out this line will make the bug go away
hook.enable();
const asyncLocalStorage = new AsyncLocalStorage();
async function main () {
// Commenting out this line will make the bug go away
await 1
asyncLocalStorage.enterWith({ foo: 'bar' });
}
await main()
console.log(executionAsyncResource());
// Should not be undefined
notEqual(asyncLocalStorage.getStore(), undefined);
Note that:
- disabling the hook solve the problem
- removing the
await 1
promise solves the problem
Debugging the executionAsyncResource()
in this case:
Promise {
<pending>,
[Symbol(async_id_symbol)]: 12,
[Symbol(trigger_async_id_symbol)]: 9
}
while in without the createHook().enable()
call:
{ [Symbol(kResourceStore)]: { foo: 'bar' } }