Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Unhandled Rejection Abort Proposal #27

Closed
@benjamingr

Description

@benjamingr

(Written by @BridgeAR and @benjamingr)

New proposal following gathering user data for the promise-use-cases talk.

Migration & Opt-out Path

We propose an environment variable called UNHANDLED_REJECTION which Node.js will use in order to determine what the behaviour for unhandled rejection is.

The environment variable can take two values abort and warn.

  • Abort enables GC unhandled rejection detection and the abort semantics
  • Warn disable the GC unhandled rejection detection and keeps the current "warn" semantics

If the user passes another value - Node.js should throw an error. We propose that the default value for the flag is warn in v10 and v8 of Node and abort from v11 on.

An environment variable has the advantage of being backportable to older versions of Node.js and makes it easier for people to upgrade and use the semantics they want. It's easy to opt-in and opt-out of the environment variable.

Actual semantics:

  • Keep the current warnings and hooks for unhandledRejection and rejectionHandled. Warning will not be printed in case you have the hook (current behaviour).
  • If promise is unhandled on garbage collection trigger an uncaught exception (crash and go through uncaughtException).
    • No need to add additional semantics for opt-out, if you want to opt-out of this you can add a .catch inside the unhandledRejection hook.
    • Add a second optional argument to uncaughtException that will allow optionally detecting if the exception originated from a promise.
      • Note that this isn't strictly necessary because of the .catch ability inside the handler but people have asked for this.

We think that a minimal implementation would be a good idea.

Future Semantics

  • Eventually combine the warn and abort semantics and move the WeakMap for unhandledRejection to C++.
  • On Exit - log all the pending unhandled rejections (explicitly let's not solve this now).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions