Skip to content

executionAsyncId doesn't return expected value in context of process.on('unhandledRejection') #26794

@isaacs

Description

@isaacs

Version: 12.0.0-pre (78162ad)
Platform: Darwin geegaw.local 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64
Subsystem: async_hooks

https://gist.github.com/isaacs/1f8c5092ba7d67d9a5f4e342ff7778b7

I am building a domain-like implementation to catch errors using async_hooks. However, the executionAsyncId is reset to 0 on an unhandledRejection event, making it impossible for me to know if I ought to handle the error or crash.

The weird thing is that it only fails in this way when the promise rejection is within an async hop, such as a setTimeout. If the promise rejection happens at the top level, then I get the expected value of 1 as the executionAsyncId.

This is preventing me moving node-tap off of core domains. Fewer modules using domains means that it could be deprecated sooner :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.confirmed-bugIssues with confirmed bugs.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