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

Swallow exceptions in terminating environments… #185

Conversation

savetheclocktower
Copy link
Contributor

@savetheclocktower savetheclocktower commented Sep 26, 2024

…triggered by nsfw async operations.

This fixes #184 and is a product of the discussion in that issue.

There appears to be an exception caused by the following chain of events:

  • NSFW loaded in a worker thread or other context-aware environment
  • start called on an NSFW instance, returning a promise
  • environment terminated (via worker.terminate() or the equivalent)
  • the start promise resolves

Ordinarily, this is a fatal error:

By default, throwing an exception on a terminating environment (eg. worker threads) will cause a fatal exception, terminating the Node process. This is to provide feedback to the user of the runtime error, as it is impossible to pass the error to JavaScript when the environment is terminating.

NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS was created to enable a mode where such exceptions are caught and swallowed so that they don't bring the entire process down.

This test in N-API itself may be useful to consult: it creates a worker, start an async operation, terminates the worker, then triggers an exception from the C++ code. The two “swallow exceptions” modes are the only ones in which the process is meant to keep going after such a failure.

I need this in an Electron environment — specifically loading nsfw in a renderer process, where a simple page reload is enough to create a terminating environment like the one in that test case.

…triggered by `nsfw` async operations.

(See https://github.com/nodejs/node-addon-api/blob/main/doc/setup.md and the section on `NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS`.)
@julianmesa-gitkraken julianmesa-gitkraken self-assigned this Sep 26, 2024
@ianhattendorf ianhattendorf merged commit b3308a9 into Axosoft:master Sep 26, 2024
15 checks passed
@savetheclocktower savetheclocktower deleted the swallow-unthrowable-exceptions-by-default branch September 26, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

“libc++abi: terminating due to uncaught exception of type Napi::Error” in terminating Electron environment
3 participants