-
Notifications
You must be signed in to change notification settings - Fork 459
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
Fatal error when using N-API async code from process exit hooks #591
Comments
Hi @rolftimmermans , I don't think you can perform asynchronous cleanup on the
|
That makes sense. I just prefer to avoid the crash. 🙂 |
Yeaaah that makes sense 😄 Well, I think this is an underlying napi issue. I would imagine the |
It might be bigger than only Thinking about this more I'd be really happy if |
I took a quick look and in EmitExit does as boolean property Even if we added something that could be easily checked in the C N-API methods (or by node-addon-api through a new method) I'm not sure the performance cost doing that check would be acceptable to provide a better error in this case. |
Is it possible to check such a condition after an error occurs? It's just that the crash that happens now is very unclear. For a consumer of an N-API library it's not easy to figure out why this is happening. I don't expect this to work, just a clearer (maaaybe, if possible, even a custom) error message... |
There would have to be some sort of crash handler which would be able to figure out
I don't have any good ideas of how to do that easily. |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
I'm also seeing this from native code that's calling back into Javascript via a |
When calling N-API based async code (in particular written with
none-addon-api
) from a process exit hookprocess.on("exit")
it leads to a fatal error.This is very easy to reproduce. For example, take the
asyncworker.js
tests and put the last block within aprocess.on("exit")
callback. Like thisRunning as
node --expose-gc test/asyncworker.js
the process is aborted and I see the following stack trace. Tested with Node.js 12.12.0 on macOS 10.14.I would expect:
I am running into this issue with zeromq.js, where I can't control users calling into the native code from an exit hook and this leads to similar fatal errors. Maybe there could be a way to check if the process/thread is exiting from within the native code?
The text was updated successfully, but these errors were encountered: