1

I have a Node addon related to a failure, when I destroy an object. I have no idea which object is causing that. Here is some features I am using.

I have a project where I create a few objects using Napi::ObjectWrap, some asynchronous functions that do CPU work in using Napi::AsyncWorker, I also keep a reference to some class definition constructors, using Napi::Persistent, and calling constructor.SuppressDestruct.

This is the error message I receive

#
# Fatal error in , line 0
# Check failed: IsEmpty().
#
#
#
#FailureMessage Object: 0x7ffc339551c0
 1: 0xb75dd1  [node]
 2: 0x1c08724 V8_Fatal(char const*, ...) [node]
 3: 0xf24789  [node]
 4: 0xf2f718 v8::internal::ScavengerCollector::CollectGarbage() [node]
 5: 0xeafa25 v8::internal::Heap::Scavenge() [node]
 6: 0xebe440  [node]
 7: 0xebee20 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: 0xec1d9e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0xe832da v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
10: 0x11fc026 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x15f0a99  [node]
Trace/breakpoint trap

Reading about IsEmpty, I suspected that this could be due to disabling C++ exceptions, my binding.gyp file has -fexceptions in both cflags and cflags_cc, and I removed a define NAPI_DISABLE_CPP_EXCEPTIONS I was using before, but the behavior stays the same.

I worked around this problem by having a global constant instance. While it worked for my current user case, for more complex cases I would like to create and destroy the objects dynamically.

Thank you in advance.

Bob
  • 13,867
  • 1
  • 5
  • 27
  • You don't destroy V8 objects - only the garbage collector can destroy them. You should simply dereference them. Can you post your object creation / object deletion code? – mmomtchev Sep 01 '22 at 23:57
  • Sorry, by destroying an object I mean dereferencing it, either by running out of scope, overriding the variable, or explicitly calling delete. Unfortunately I couldn't craft a minimal reproducible example. – Bob Sep 02 '22 at 09:35
  • Do you know at least how I could use the Object number to know what the object was? – Bob Sep 02 '22 at 09:44
  • From what I understand, there is a certain object that when it is a global instance, does not lead to a crash, and when it is dynamically allocated - it does lead to a crash. Can you post this code? – mmomtchev Sep 02 '22 at 12:02
  • It is not open source, but even if I get the permission to post it here, what is the maximum amount of code that would be reasonable for a stack overflow question? Certainly not 2k lines of code, added to that the third party code and libraries, it is about half an hour to build, and if you want to see the error you may have to wait for a script running a few minutes. This is why I preferred to write this in a high level. – Bob Sep 02 '22 at 12:39
  • If you can create a toy example and show how to proceed with the investigation of this type of issue, that is is an acceptable answer. – Bob Sep 02 '22 at 12:48
  • 1
    You are doing something with an object that you are not supposed to. You can try a full debug build of Node.js/V8 which will give you a little bit more information. It is not very easy to unwrap and print the object in the garbage collector where your crash is - and you probably do not need to go down so deep. You are not supposed to be deleting `ObjectWrap` objects. Also, you are not supposed to be directly creating them - you should inherit from this class to define your own objects. – mmomtchev Sep 02 '22 at 14:05

0 Answers0