Skip to content

unhandledRejection falls into infinite recursion #17913

@eduardbme

Description

@eduardbme
  • Version: 8+ (probably all versions that supports unhandledRejection event)
  • Platform: linux
  • Subsystem: process

According to documentation of uncaughtException - 'Exceptions thrown from within the event handler will not be caught. Instead the process will exit with a non-zero exit code and the stack trace will be printed. This is to avoid infinite recursion.'.

So why unhandledRejection allows you to fall into infinite recursion if code within handler creates unhandled promise rejection ? I expect the same behavior as for uncaughtException (exit process with non-zero code).

unhandledRejection handler may contain some logic to log that situation, and owing to the fact that 3-d party logger implementation can produce unhandled rejection within himself , we can have infinite recursion.

Code example to reproduce:

'use strict';

process.on('unhandledRejection', uncaughtRejection => {
    console.log('unhandledRejection handler catch: ' + uncaughtRejection);

    Promise.reject(3);
});

function foo() {
    return Promise.reject(1);
}

foo();

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    promisesIssues and PRs related to ECMAScript promises.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions