Skip to content

🐛 Bug: unhandledRejection events are re-emitted #4743

Open

Description

process.emit('unhandledRejection', reason, promise);

What is the use case for this code here?
I got surprised by seeing the handler executed twice whenever rejecting a promise. For example

it('runs example', () => {
        Promise.reject('nobody handles me 😈 '); // reject once
        process.on('unhandledRejection', (reason, promise) => {
            console.log(' Rejection ', reason, JSON.stringify(promise)); // this shows up twice
        });
})

I notice the handler was removed(line 198) before the rejection is emitted internally in mocha, but the event seems to be cached, which means the internal emit will trigger the handler to be called anyway right after it is added back (line 206).

Is it intended to be so (what is the use case if this is true) or it is some bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area: node.jscommand-line-or-Node.js-specificstatus: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions