Skip to content

Throw within queueMicrotask callbacks should not crash Node #38145

Open
@Huxpro

Description

@Huxpro
  • Version:v15.9.0
  • Platform: macOS x86
  • Subsystem: task_queues

What steps will reproduce the bug?

λ node --trace-uncaught
Welcome to Node.js v15.9.0.
Type ".help" for more information.
> queueMicrotask(_ => { throw 1 });
undefined
>
node:internal/process/task_queues:94
    runMicrotasks();
    ^
1
Thrown at:
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

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

Always.

What is the expected behavior?

If I understood the spec correct:

The queueMicrotask(callback) method must queue a microtask to invoke callback, and if callback throws an exception, report the exception.

It should behave similarly as Timer tasks.

> setTimeout(_ => {throw 1});
Timeout {
  ...
}
> Uncaught 1

What do you see instead?

Node crashed

Additional information

I did some preliminary triages that hopefully helps a bit:

  • task_queues.js invoke runMicrotask
  • which is a JS binding from node_task_queue.cc which invokes V8's PerformCheckpoint under the hood.
  • V8's PerformCheckpoint invoked V8's RunMicrotasks to actually evaluate those JS callbacks.

But since V8's PerformCheckpoint returns void. I'm not sure how can Node be aware of any exceptions threw during the evaluation of those JS callbacks. Chromium seems to handle this fine but I haven't got time looking at its source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.processIssues and PRs related to the process subsystem.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions