-
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
(Typed)ThreadSafeFunction.Release() crashes renderer process on reload (& abort?) #1109
Comments
@robinchrist if you remove the |
@gabrielschulhof I am debugging what seems to be the same issue and I did
If I remove the call to Currently the only way to make this work is to always have a finalizer and defer the deleting of the containing object. It is quite cumbersome, isn't it possible to skip |
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. |
@gabrielschulhof What would be the best way to test this? |
I have the same problem on mac, but I can't trigger the bug stably.
I wrote something like this. See the full version here.
Here is my crash log.
|
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. |
Hi @robinchrist / @mmomtchev / @BB-fat , We discussed this in the 1 July Node API meeting. Do you have a repository that reproduces this issue? Since this is using Electron, it is a little cumbersome to try to create a repro on our own. Thanks, Kevin |
@KevinEady I don't have a repro, but this is not limited to Electron and it is not a bug but a design oversight. From memory (this is the reason I don't use the C++ |
Hi @mmomtchev , That logic does follow. However from what I'm seeing in the code for the finalize wrappers, these just call the finalizer with the data and context as decided in the Are you using a finalizer callback or data that is held by the C++ object you are Unless I am misunderstanding something...? |
Yes indeed they are static, it might have been the data then, I will try to revert to |
So what is the right way to release a |
Hi @robinchrist , In my threadsafe-function |
Yes, but that's not really a solution. The TSFN is held for a longer time and the objects which contain the TSFN are created and destroyed on the fly. There must be a way to properly release a TSFN that is the member of an object inside the object's destructor? |
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. |
We discussed this in the 7 Oct Node API meeting.
Both of the stacktraces posted above have a call to |
@robinchrist is there any chance you could run under valgrind? That might give us more info on specifically what is leading to the crash. There are some instructions in https://github.com/nodejs/node/blob/main/doc/contributing/investigating-native-memory-leaks.md |
Chiming in here to say I have this issue! |
I've submitted an explicit document on the order of invocation of |
We discussed this issue in the 24 Feb Node API team meeting. There is a backing PR (nodejs/node#46692) in core to verify the order as described in nodejs/node#45903. Once the test PR has been merged, we can merge the documentation PR. |
I think we need to thoroughly examine all the places where we NAPI_FATAL_IF_FAILED and decide if we need to add a NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS section. For example, at Line 2940 in 5adb896
napi_define_properties() fails.
|
It seems feasible to call // jsCallback is an Napi::ThreadSafeFunction
void MyObject::Finalize(const Napi::Env env) {
if (jsCallback) {
jsCallback.Release();
jsCallback = nil;
}
} |
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. |
We are using a native addon with Electron (Both v14 and v16 show the same behaviour)
There is a class, which roughly looks like this:
Everything works fine - Except when Electron reloads.
There are some situation when we need to reload the Electron application via
getCurrentWebContents().reloadIgnoringCache()
- Which fails spectacularly with a renderer crash.This is an issue both for our users AND when in development when using hot reload.
I have tracked down the issue to the
.Release()
callsIf I remove the
.Release()
calls, everything seems to work fine, including reload.I have tried to debug the issue further with a debug build of Electron, but at least v14 (have not tested v16) triggers another assertion when reloading which can't be fixed (I stripped the addon to not contain any exports and just the register call and it still caused a renderer crash on reload with Debug Electron)
My theory: Node destroys the TSFNs on Node's side before it frees / destroys the objects of the addon. I can't say whether this is just a wild theory or a real explanation, but I think a couple of Node devs here could know?
Our fix for now: Don't free the TSNFs in the destructor. The
Foo
object is long-living and usually only created once and destroyed once in the lifecycle of the addon.FWIW, that's the stacktrace:
Electron versions: v14 & v16
Compiler: Clang 10+
OS: definitely Linux, but seems to happen on MacOS and Windows
Arch: AMD64, but seems to happen on ARM64 too
Any ideas?
The text was updated successfully, but these errors were encountered: