Repository navigation
Closed
Description
I update to node-addon-api 1.5.0 (from 1.4.0) and I got this error at runtime using gdb
#
# Fatal error in , line 0
# Check failed: !value_obj->IsJSReceiver() || value_obj->IsTemplateInfo().
#
#
#
#FailureMessage Object: 0x7fffffffb220
Thread 1 "node" received signal SIGILL, Illegal instruction.
0x00000000016abfa9 in v8::base::OS::Abort() ()
and this stack
#0 0x00000000016abfa9 in v8::base::OS::Abort() ()
#1 0x00000000016a8a94 in V8_Fatal(char const*, int, char const*, ...) ()
#2 0x0000000000b04353 in v8::Template::Set(v8::Local<v8::Name>, v8::Local<v8::Data>, v8::PropertyAttribute) ()
#3 0x00000000008eac00 in napi_define_class ()
#4 0x00007ffff406c218 in Napi::ObjectWrap<genepi::ClassWrapper<Test> >::DefineClass(Napi::Env, char const*, unsigned long, napi_property_descriptor const*, void*) ()
from /home/camaud/programming/genepi/build/Release/genepi.node
#5 0x00007ffff406e10c in genepi::BindClass<Test>::initialize(Napi::Env&, Napi::Object&) const () from /home/camaud/programming/genepi/build/Release/genepi.node
#6 0x00007ffff406f322 in initialize(Napi::Env, Napi::Object) () from /home/camaud/programming/genepi/build/Release/genepi.node
#7 0x00007ffff406f4ac in __napi_initialize(napi_env__*, napi_value__*) () from /home/camaud/programming/genepi/build/Release/genepi.node
#8 0x00000000008e14a1 in napi_module_register_by_symbol(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>, napi_value__* (*)(napi_env__*, napi_value__*)) ()
#9 0x00000000008d3352 in node::DLOpen(v8::FunctionCallbackInfo<v8::Value> const&) ()
#10 0x0000000000b8b32f in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) ()
#11 0x0000000000b8be99 in v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) ()
Do you have an idea why this crashes in 1.5.0 and not in 1.4.0? I had the same crash on several computers with several gcc and node versions. Any major changes in Napi::ObjectWrap::DefineClass?
Thanks for your help!
Metadata
Metadata
Assignees
Labels
No labels
Activity
gabrielschulhof commentedon Oct 19, 2018
@BotellaA which precise versions of Node.js have you tried this with? We've had crashes caused by Node.js itself, because it was accessing a stale pointer as part of the execution of
OnOK.BotellaA commentedon Oct 19, 2018
I tried 8.12, 10.11 and 10.12.
mhdawson commentedon Oct 19, 2018
Changelog is here: https://github.com/nodejs/node-addon-api/blob/master/CHANGELOG.md
mhdawson commentedon Oct 19, 2018
If we have them properly labelled then these should be the only candiates:
[917bd60] - src: remove TODOs by fixing memory leaks (Gabriel Schulhof) #343
[dfcb939] - src: implement AsyncContext class (Jinho Bang) #252
[211ed38] - src: make 'nothing' target a static library (Gabriel Schulhof) #348
[97c4ab5] - src: add Call and MakeCallback that accept cargs (NickNaso) #344
[b6e2d92] - src: enable DataView feature by default (Jinho) #331
[0a00e7c] - src: implement missing descriptor defs for symbols (Philipp Renoth) #280
[38e01b7] - src: first pass on adding version management apis (NickNaso) #325
[79ee838] - src: fix compile failure in test (Michael Dawson) #345
[4d92a60] - src: Add ObjectReference test case (Anisha Rohra) #212
mhdawson commentedon Oct 19, 2018
Guessing that we can eliminate ones which add new functionality, which I think leaves this one unless we have some problems with the instance of a method with the wrong parameters being selected because there are additional options is a possibility(for example [97c4ab5] - src: add Call and MakeCallback that accept cargs (NickNaso) #344)
[917bd60] - src: remove TODOs by fixing memory leaks (Gabriel Schulhof) #343
mhdawson commentedon Oct 19, 2018
I believe [917bd60] did affect the functionality for define class as well, so probably a good candidate.
mhdawson commentedon Oct 19, 2018
@gabrielschulhof since you are already engaged maybe you can help @BotellaA revert that change and see if it is related?
gabrielschulhof commentedon Oct 19, 2018
@BotellaA can you rebuild with
--debugso I can see line numbers on the node-addon-api part of the stack? I suspect that a function-valued property gets added as an instance method. This is not allowed.Also, can you point me to the source code, if it's open?
BotellaA commentedon Oct 19, 2018
Here is the debug stack
The code is not open yet but if we cannot find the issue, I will send some files to you.
BotellaA commentedon Oct 20, 2018
I read the commit
[917bd60] - src: remove TODOs by fixing memory leaks (Gabriel Schulhof) #343and I see now why my code does not work anymore.The idea is to have an automatic wrapper arround a custom class
Bound. I have the list of all static function and method pointers. I want to hook to these pointers to theClassWrapperinstance.The trick is that the methods are not defined in the
ClassWrapper, they are defined as classic C++ functions. So I can only use yourStaticMethodhelper function but I want to use them as a method from the JS side. Removing thenapi_staticflag does the trick.To sum up (because I am not sure to be clear...), I want a
StaticMethodof Napi but a classic method from JS side. I think this trick can no longer be done with your new implementation ofDefineClass.gabrielschulhof commentedon Oct 21, 2018
@BotellaA Each function and accessor you define causes the wrapper to allocate data on the heap. This data has to be deleted when it is clear that the accessor or the function will never be called again. It will usually never be called again when it has been garbage-collected. In the case of JS classes this means that the data associated with accessors and prototype methods will be deleted when the JS class itself is garbage-collected, and in the case of static methods the data will be deleted when the static methods are garbage collected, because the static methods can be detached from the class and thus may outlive the class. To reflect this, the new implementation converts static method descriptions to
Napi::Functions before callingnapi_define_class, and attaches the heap-allocated data to theNapi::Function.So the reason this does not work anymore is that V8 crashes when attempting to attach a ready-made
Napi::Functionto the JS class prototype.BotellaA commentedon Oct 21, 2018
@gabrielschulhof Ok, I understand the need to create
Napi::Functions but not really how to make this design to work... Any recommendation?gabrielschulhof commentedon Oct 22, 2018
@BotellaA you can always reach down into N-API for custom behaviour:
Header:
https://github.com/gabrielschulhof/node-addon-examples/blob/5c6c9731b1e337650d887c30b990437d67e43e30/6_object_wrap/node-addon-api/myobject.h#L17
Implementation:
https://github.com/gabrielschulhof/node-addon-examples/blob/5c6c9731b1e337650d887c30b990437d67e43e30/6_object_wrap/node-addon-api/myobject.cc#L5
BotellaA commentedon Oct 22, 2018
@gabrielschulhof Thanks, I will look into this. Since the error is not on your side, I close the issue.