Skip to content

if uncaughtExceptionMonitor handler throws asynchronously, the process enters infinite async recursion #38281

Open
@MadaraUchiha

Description

@MadaraUchiha
  • Version: v15.14.0
  • Platform: all
  • Subsystem: process/execution

What steps will reproduce the bug?

  1. Register an uncaughtExceptionMonitor handler on process, which itself throws asynchronously
  2. Throw an error

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

What is the expected behavior?

I'm not sure what should happen here, currently the entire uncaughtException chain is handled synchronously, I'm not certain what adding async to the mix would do. Please advise.

What do you see instead?

Process enters an infinite asynchronous recursion, whereby the monitor invokes the uncaughtRejection which invokes the uncaughtExceptionMonitor and vice versa.

Additional information

Example file:

process.addListener('uncaughtExceptionMonitor', async (e) => {
  console.error('Monitored Error!', e);
  throw new Error('Oopsie!');

});

process.addListener('uncaughtException', e => {
  console.error('Handled error!', e);
})
let i = 0;
setInterval(() => console.log(i++), 1000);
throw new Error('Thrown!');

Output:

...
...
...
Monitored Error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
Handled error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
Monitored Error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
Handled error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
^C

(only stops at interrupt)

Metadata

Metadata

Assignees

No one assigned

    Labels

    processIssues and PRs related to the process subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions