Skip to content

Promise hooks don't work well in vm contexts #38781

Description

@targos

After #36394, the following test is broken:

constvm=require('vm');const{ AsyncLocalStorage }=require('async_hooks')constcontext=vm.createContext({
AsyncLocalStorage,
console,});vm.runInContext(` const storage = new AsyncLocalStorage() async function test() { return storage.run({ test: 'vm' }, async () => { console.log(storage.getStore()); await 42; console.log(storage.getStore()); }); } test()`,context);conststorage=newAsyncLocalStorage()asyncfunctiontest(){returnstorage.run({test: 'main context'},async()=>{console.log(storage.getStore());await42;console.log(storage.getStore());});}test()

Node 16.1.0:

{ test: 'vm' }
{ test: 'main context' }
{ test: 'vm' }
{ test: 'main context' }

Node 16.2.0:

{ test: 'vm' }
{ test: 'main context' }
undefined
{ test: 'main context' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.confirmed-bugIssues with confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions