Open
Description
I have an Electron app which uses node-addon-api to retrieve and access a number of objects written in C++. After the app has been running for a long time and not received further usage (typically 12+ hours), it often will crash when I attempt to use it again. I suspect something is being garbage collected (the exported class?) during this period of no usage, so trying to access it later is what causes the crash.
I have collected a number of stack traces, but this is a good one since it should be just calling a static method with an int.
***** FATAL SIGNAL RECEIVED *******
Received fatal signal: SIGSEGV(11) PID: 48583
***** SIGNAL SIGSEGV(11)
******* STACKDUMP *******
stack dump [1] (anonymous namespace)::signalHandler(int, __siginfo*, void*) + 97
stack dump [2] _sigtramp + 29
stack dump [3] 3 soulsifter.node 0x0000000110deff00 soulsifter.node + 1474304
stack dump [4] PlaylistEntry::findByPlaylistId(Napi::CallbackInfo const&) + 314
stack dump [5] napi_value__* Napi::details::TemplatedCallback<&(PlaylistEntry::findByPlaylistId(Napi::CallbackInfo const&))>(napi_env__*, napi_callback_info__*) + 33
stack dump [6] 6 Electron Framework 0x0000000119a3deac napi_is_detached_arraybuffer + 396
stack dump [7] 7 Electron Framework 0x00000001118d423f Electron Framework + 225855
stack dump [8] 8 Electron Framework 0x00000001118d1ea7 Electron Framework + 216743
Exiting after fatal event (FATAL_SIGNAL). Fatal type: SIGSEGV
My related code:
Napi::Object PlaylistEntry::Init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(env, "PlaylistEntry", {
...
StaticMethod<&PlaylistEntry::findByPlaylistId>("findByPlaylistId"),
});
constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
exports.Set("PlaylistEntry", func);
return exports;
}
Napi::Value PlaylistEntry::findByPlaylistId(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() < 1) {
Napi::TypeError::New(env, "Expected at least 1 argument.").ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsNumber()) {
Napi::TypeError::New(env, "TypeError: Number expected (for info[0])").ThrowAsJavaScriptException();
return env.Null();
}
int32_t a0(info[0].As<Napi::Number>().Int32Value());
dogatech::ResultSetIterator<dogatech::soulsifter::PlaylistEntry>* result =
dogatech::soulsifter::PlaylistEntry::findByPlaylistId(a0);
vector<dogatech::soulsifter::PlaylistEntry*>* v = result->toVector();
Napi::Array a = Napi::Array::New(env, static_cast<int>(v->size()));
for (int i = 0; i < (int) v->size(); i++) {
Napi::Object instance = PlaylistEntry::NewInstance(env);
PlaylistEntry* r = Napi::ObjectWrap<PlaylistEntry>::Unwrap(instance);
r->setWrappedValue((*v)[i], true);
a.Set(i, instance);
}
delete v;
return a;
}
.. and in the module init file:
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
...
PlaylistEntry::Init(env, exports);
...
return exports;
}
NODE_API_MODULE(soulsifter, InitAll)
Any insight or help would be appreciated, and let me know if you believe this is an issue for Electron instead.
Thanks!
Metadata
Assignees
Labels
No labels