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

n-api: defer Buffer finalizer with SetImmediate #28082

Closed
wants to merge 2 commits into from

Commits on Jun 5, 2019

  1. src: fix off-by-one error in native SetImmediate

    Previously, the throwing callback would have been re-executed in case
    of an exception. This patch corrects the calculation to exclude the
    callback.
    addaleax committed Jun 5, 2019
    Configuration menu
    Copy the full SHA
    24a1905 View commit details
    Browse the repository at this point in the history
  2. n-api: defer Buffer finalizer with SetImmediate

    We have a test that verifies that JS execution from the Buffer
    finalizer is accepted, and that errors thrown are passed
    down synchronously.
    
    However, since the finalizer executes during GC, this is behaviour is
    fundamentally invalid and, for good reasons, disallowed by the
    JS engine. This leaves us with the options of either finding a way
    to allow JS execution from the callback, or explicitly forbidding it on
    the N-API side as well.
    
    This commit implements the former option, since it is the more
    backwards-compatible one, in the sense that the current situation
    sometimes appears to work as well and we should not break that
    behaviour if we don’t have to, but rather try to actually make it
    work reliably.
    
    Since GC timing is largely unobservable anyway, this commit moves
    the callback into a `SetImmediate()`, as we do elsewhere in the code,
    and a second pass callback is not an easily implemented option,
    as the API is supposed to wrap around Node’s `Buffer` API.
    In this case, exceptions are handled like other uncaught exceptions.
    
    Two tests have to be adjusted to account for the timing difference.
    This is unfortunate, but unavoidable if we want to conform to the
    JS engine API contract and keep all tests.
    
    Fixes: nodejs#26754
    addaleax committed Jun 5, 2019
    Configuration menu
    Copy the full SHA
    26e2141 View commit details
    Browse the repository at this point in the history