Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_hooks: make AsyncResource safer #18513

Merged
merged 1 commit into from
Feb 9, 2018

Commits on Feb 9, 2018

  1. async_hooks: deprecate unsafe emit{Before,After}

    The emit{Before,After} APIs in AsyncResource are problematic.
    
    * emit{Before,After} are named to suggest that the only thing they do
      is emit the before and after hooks. However, they in fact, mutate
      the current execution context.
    * They must be properly nested. Failure to do so by user code leads
      to catastrophic (unrecoverable) exceptions. It is very easy for the
      users to forget that they must be using a try/finally block around
      the code that must be surrounded by these operations. Even the
      example provided in the official docs makes this mistake. Failing
      to use a finally can lead to a catastrophic crash if the callback
      ends up throwing.
    
    This change provides a safer `runInAsyncScope` API as an alternative
    and deprecates emit{Before,After}.
    
    PR-URL: nodejs#18513
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
    ofrobots committed Feb 9, 2018
    Configuration menu
    Copy the full SHA
    523a155 View commit details
    Browse the repository at this point in the history