Skip to content

if uncaughtExceptionMonitor handler throws, the process dies without chance for recovery by uncaughtException or uncaughtRejection #38280

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
  2. Throw an error without catching it

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

Every time.

What is the expected behavior?

uncaughtException event on process to be fired, if error is handled don't crash the process.

  • Ideally with an AggregateError containing both errors
  • But at least with the original error

What do you see instead?

The process simply dies with error code 7. uncaughtException isn't emitted.

Additional information

Example file:

process.addListener('uncaughtExceptionMonitor', (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!');

Expected

Monitored: ...
Handled: ...
0
1
2
...

Actual

Monitored: ...
/path/to/test.js:3
  throw new Error('Oopsie!');
  ^

Error: Oopsite!
    at ...

$ # process died, error code is 7

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