You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When importing Realm in an electron renderer process with nodeIntegration enabled, the renderer process will crash every time when reloading the BrowserWindow.
This is enough to cause it.
// preload.jsconstRealm=require('realm');
It appears to me that the root cause is something to do with the re-import of the NAPI module.
Creating a Persistent NAPI object in node_class.hpp fails due to the reference in napi trying to reset and removing itself.
napi_status status = napi_delete_reference(_env, _ref);
I am not pretending to actually know anything about this as I'm not familiar with node native modules or c++ really, but I found an issue from 2018 that referenced problems with static references (even though supposedly fixed). nodejs/node-addon-api#162.
For what it's worth I was able to produce a version that doesn't crash anymore (obviously without any actual working functionality) by building a dummy of napi_init where the persistent object is scoped to the function. Now I realise that this might not actually help anything but I thought I'd report the find.
staticvoidnapi_init(Napi::Env env, Napi::Object exports)
{
Napi::FunctionReference test;
auto setPrototypeOf = env.Global().Get("Object").As<Napi::Object>().Get("setPrototypeOf").As<Napi::Function>();
test = Napi::Persistent(setPrototypeOf);
// node_class_init(env);// Napi::Function realm_constructor = js::RealmClass<Types>::create_constructor(env);// std::string name = realm_constructor.Get("name").As<Napi::String>();// exports.Set(Napi::String::New(env, name), realm_constructor);
}
I'm reporting this here because I'm unsure who is actually responsible for a fix, but it seems like that the either it is impossible to store the function references as static objects like done here or there is an issue with napi not handling that case correctly even though it should.
Let me know if you need any more information, cheers.
Hi @BFriedrichs, could you clarify how you are "reloading the BrowserWindow"? I'm not an expert on Electron, if you're able to supply a simple reproduction project and instructions that would be really helpful! Thanks
Edit: Also, to answer your question. Literally any action that refreshes the embedded browser contents which causes 'preload.js' to be executed again causes this issue as far as I can tell. That includes window.location.reload() or pressing CMD+R but also live-reload features as you would expect from various webpack related projects.
Great, thanks for the repro and I can confirm that it crashes here. We'll have to do some investigation into whether this is something we can fix or provide a workaround for, we will update this ticket when we've been able to take a look.
How frequently does the bug occur?
All the time
Description
When importing Realm in an electron renderer process with
nodeIntegration
enabled, the renderer process will crash every time when reloading the BrowserWindow.This is enough to cause it.
It appears to me that the root cause is something to do with the re-import of the NAPI module.
Creating a Persistent NAPI object in
node_class.hpp
fails due to the reference in napi trying to reset and removing itself.The crash is initiated by:
realm-js/src/node/node_class.hpp
Line 63 in bef8c3a
And ultimately causes a segfault at:
https://github.com/nodejs/node-addon-api/blob/9bea434326d5e6c6fa355a51b6f232a503521a21/napi-inl.h#L2975
I am not pretending to actually know anything about this as I'm not familiar with node native modules or c++ really, but I found an issue from 2018 that referenced problems with static references (even though supposedly fixed).
nodejs/node-addon-api#162.
For what it's worth I was able to produce a version that doesn't crash anymore (obviously without any actual working functionality) by building a dummy of napi_init where the persistent object is scoped to the function. Now I realise that this might not actually help anything but I thought I'd report the find.
I'm reporting this here because I'm unsure who is actually responsible for a fix, but it seems like that the either it is impossible to store the function references as static objects like done here or there is an issue with napi not handling that case correctly even though it should.
Let me know if you need any more information, cheers.
Stacktrace & log output
Can you reproduce the bug?
Yes, always
Reproduction Steps
Import Realm in a electron renderer process while nodeIntegration is enabled and reload the window.
Version
10.14.0
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
macOS 12.1
Build environment
Which debugger for React Native: ..
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: