Skip to content

SourceTextModule w/ microtaskMode "afterEvaluate" breaks program execution flow #59541

@ericrannaud

Description

@ericrannaud

Version

v24.5.0

Platform

Linux hostname 6.10.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 19 Aug 2024 17:02:39 +0000 x86_64 GNU/Linux

Subsystem

vm

What steps will reproduce the bug?

import * as vm from "node:vm";

const context = vm.createContext({}, {
  microtaskMode: "afterEvaluate",
});

const m = new vm.SourceTextModule(
  "",
  {context},
);

await m.link(() => null);
await m.evaluate();

console.log("This is never printed, but the node process terminates.");

How often does it reproduce? Is there a required condition?

Repeats every time.

What is the expected behavior? Why is that the expected behavior?

With this module source code (the empty string in this example, but it also happens with non-trivial code in the module), the program behavior should be the same whether the microtaskMode is set to "afterEvaluate" or left unspecified. The console.log() statement should be printed.

What do you see instead?

Node terminates without executing the console.log() statement. Node reports:

Warning: Detected unsettled top-level await at file:///tmp/test2.js:13
await m.evaluate();
^

If you comment out the line setting microtaskMode, the console.log() statement is executed as expected.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions