Skip to content

function_reference test failure when using Debug build of node v20.13.1 #1511

Closed

Description

@KevinEady

Using node v20.13.1 built with debug configuration according to Building: Building a debug build fails:

> node-addon-api@8.0.0 test
> /Users/kevineady/Projects/node/out/Debug/node test

napiVersion:9
Testing with Node-API Version '9'.
Starting test suite

Running test 'addon'
Running test 'addon_build'
....
Running test 'function_reference'


#
# Fatal error in ../deps/v8/src/objects/tagged-impl.h, line 142
# Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)).
#
#
#
#FailureMessage Object: 0x16afc4988
----- Native stack trace -----

 1: 0x104ef3bd8 node::DumpNativeBacktrace(__sFILE*) [/Users/kevineady/Projects/node/out/Debug/node]
 2: 0x105142570 node::NodePlatform::GetStackTracePrinter()::$_3::operator()() const [/Users/kevineady/Projects/node/out/Debug/node]
 3: 0x10514252c node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/Users/kevineady/Projects/node/out/Debug/node]
 4: 0x106f645d4 V8_Fatal(char const*, int, char const*, ...) [/Users/kevineady/Projects/node/out/Debug/node]
 5: 0x106f64170 std::__1::enable_if<!std::is_function<std::__1::remove_pointer<char>::type>::value && !std::is_enum<char>::value && has_output_operator<char, v8::base::CheckMessageStream>::value, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::type v8::base::PrintCheckOperand<char>(char) [/Users/kevineady/Projects/node/out/Debug/node]
 6: 0x1054d6ce4 v8::internal::Object::IsApiCallResultType() const [/Users/kevineady/Projects/node/out/Debug/node]
 7: 0x1054d6b28 v8::internal::Handle<v8::internal::Object> v8::internal::CustomArguments<v8::FunctionCallbackInfo<v8::Value>>::GetReturnValue<v8::internal::Object>(v8::internal::Isolate*) const [/Users/kevineady/Projects/node/out/Debug/node]
 8: 0x1054d6974 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/kevineady/Projects/node/out/Debug/node]
 9: 0x1054d56e0 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::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, unsigned long*, int) [/Users/kevineady/Projects/node/out/Debug/node]
10: 0x1054d4304 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/Users/kevineady/Projects/node/out/Debug/node]
11: 0x1064a24a4 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit [/Users/kevineady/Projects/node/out/Debug/node]
12: 0x106407404 Builtins_InterpreterEntryTrampoline [/Users/kevineady/Projects/node/out/Debug/node]
13: 0x106407404 Builtins_InterpreterEntryTrampoline [/Users/kevineady/Projects/node/out/Debug/node]
14: 0x106407404 Builtins_InterpreterEntryTrampoline [/Users/kevineady/Projects/node/out/Debug/node]
15: 0x10cb233d0 
16: 0x1064437d0 Builtins_AsyncFunctionAwaitResolveClosure [/Users/kevineady/Projects/node/out/Debug/node]
17: 0x106519480 Builtins_PromiseFulfillReactionJob [/Users/kevineady/Projects/node/out/Debug/node]
18: 0x1064309ec Builtins_RunMicrotasks [/Users/kevineady/Projects/node/out/Debug/node]
19: 0x106404cd4 Builtins_JSRunMicrotasksEntry [/Users/kevineady/Projects/node/out/Debug/node]
20: 0x1056db714 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/kevineady/Projects/node/out/Debug/node]
21: 0x1056dc6f4 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/kevineady/Projects/node/out/Debug/node]
22: 0x1056dcca8 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [/Users/kevineady/Projects/node/out/Debug/node]
23: 0x1057272b4 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/Users/kevineady/Projects/node/out/Debug/node]
24: 0x10572702c v8::internal::MicrotaskQueue::PerformCheckpointInternal(v8::Isolate*) [/Users/kevineady/Projects/node/out/Debug/node]
25: 0x104e3548c node::InternalCallbackScope::Close() [/Users/kevineady/Projects/node/out/Debug/node]
26: 0x104e352a8 node::InternalCallbackScope::~InternalCallbackScope() [/Users/kevineady/Projects/node/out/Debug/node]
27: 0x104e34db8 node::InternalCallbackScope::~InternalCallbackScope() [/Users/kevineady/Projects/node/out/Debug/node]
28: 0x105039684 node::fs::FSReqPromise<node::AliasedBufferBase<double, v8::Float64Array>>::Resolve(v8::Local<v8::Value>) [/Users/kevineady/Projects/node/out/Debug/node]
29: 0x105055178 node::fs::AfterNoArgs(uv_fs_s*) [/Users/kevineady/Projects/node/out/Debug/node]
30: 0x10503b16c node::MakeLibuvRequestCallback<uv_fs_s, void (*)(uv_fs_s*)>::Wrapper(uv_fs_s*) [/Users/kevineady/Projects/node/out/Debug/node]
31: 0x1063d8584 uv__fs_done [/Users/kevineady/Projects/node/out/Debug/node]
32: 0x1063ca6d4 uv__work_done [/Users/kevineady/Projects/node/out/Debug/node]
33: 0x1063d3690 uv__async_io [/Users/kevineady/Projects/node/out/Debug/node]
34: 0x1063f6f08 uv__io_poll [/Users/kevineady/Projects/node/out/Debug/node]
35: 0x1063d4090 uv_run [/Users/kevineady/Projects/node/out/Debug/node]
36: 0x104e38540 node::SpinEventLoopInternal(node::Environment*) [/Users/kevineady/Projects/node/out/Debug/node]
37: 0x1050cf80c node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/Users/kevineady/Projects/node/out/Debug/node]
38: 0x1050cf3d8 node::NodeMainInstance::Run() [/Users/kevineady/Projects/node/out/Debug/node]
39: 0x104fb1cd0 node::StartInternal(int, char**) [/Users/kevineady/Projects/node/out/Debug/node]
40: 0x104fb18ec node::Start(int, char**) [/Users/kevineady/Projects/node/out/Debug/node]
41: 0x10699a1c4 main [/Users/kevineady/Projects/node/out/Debug/node]
42: 0x18d1d1058 start [/usr/lib/dyld]
Tests aborted with SIGTRAP

The same failure happens when calling node --expose-gc test/function_reference.js directly, so the failure is not related to other tests.

Activity

  1. github-actions commented on Sep 3, 2024

    @github-actions
    Contributor

    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.

  2. KevinEady commented on Jun 27, 2025

    @KevinEady
    ContributorAuthor

    @KevinEady to check if this is still the case

  3. self-assigned this
    on Jun 27, 2025
  4. KevinEady commented on Jul 3, 2025

    @KevinEady
    ContributorAuthor

    The error has changed to a SEGV on debug version of Node.js v22.17.0.

    I've pinpointed it to this line:
    https://github.com/KevinEady/node-addon-api/blob/600fe6c114a127ea11fc7909e08bf623dfadea95/test/function_reference.js#L55

    But it is not an issue with the C++ function ConstructRefFromExisitingRef itself ... It seems to be the caller calling it.

    Image
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1baddead0baddeae)
      * frame #0: 0x0000000101b5cbe8 node`Builtins_DeoptimizationEntry_Eager + 1903592
        frame #1: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #2: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #3: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #4: 0x00000001019997cc node`Builtins_DeoptimizationEntry_Eager + 55244
        frame #5: 0x00000001019994b4 node`Builtins_DeoptimizationEntry_Eager + 54452
        frame #6: 0x000000010096f678 node`v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [inlined] v8::internal::GeneratedCode<unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, long, unsigned long**>::Call(this=<unavailable>, args=<unavailable>, args=<unavailable>, args=<unavailable>, args=<unavailable>, args=<unavailable>, args=<unavailable>) at simulator.h:178:12 [opt]
        frame #7: 0x000000010096f674 node`v8::internal::(anonymous namespace)::Invoke(isolate=<unavailable>, params=<unavailable>) at execution.cc:418:22 [opt]
        frame #8: 0x000000010096ea44 node`v8::internal::Execution::Call(isolate=0x0000000148008000, callable=Handle<v8::internal::Object> @ x23, receiver=Handle<v8::internal::Object> @ x22, argc=2, argv=0x000000016fdf38a0) at execution.cc:504:10 [opt]
        frame #9: 0x00000001006758a0 node`v8::Function::Call(this=0x000000016fdf5990, context=<unavailable>, recv=Local<v8::Value> @ x21, argc=2, argv=0x000000016fdf38a0) at api.cc:5485:7 [opt]
        frame #10: 0x0000000100521878 node`node::inspector::(anonymous namespace)::InspectorConsoleCall(info=0x000000016fdf58e8) at inspector_js_api.cc:212:35
        frame #11: 0x000000010199e3d8 node`Builtins_DeoptimizationEntry_Eager + 74712
        frame #12: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #13: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #14: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #15: 0x000000010199c330 node`Builtins_DeoptimizationEntry_Eager + 66352
        frame #16: 0x00000001019ddcf0 node`Builtins_DeoptimizationEntry_Eager + 335088
    
  5. KevinEady commented on Jul 11, 2025

    @KevinEady
    ContributorAuthor

    We discussed this in the 11 July Node-API Meeting.

    We need to identify if there is a problem with (1) our use of the APIs or (2) how the Node.js Debug build executes our addon.

    The test failing is a "move function reference test"

    Value ConstructRefFromExisitingRef(const CallbackInfo& info) {
    HandleScope scope(info.Env());
    FunctionReference ref;
    FunctionReference movedRef;
    ref.Reset(info[0].As<Function>());
    movedRef = std::move(ref);
    return MaybeUnwrap(movedRef({}));
    }
    ... Is it possible that Node.js engine has an old pointer for the moved function, since our Napi::Functions are being called and returned correctly -- both the function_reference.js call to our addon's ConstructRefFromExisitingRef, as well as this function's call to movedRef({}).

    @legendecas mentioned he will take a look when he gets a chance ... This is a bit too in the weeds of my Node.js knowledge to troubleshoot any further 😅

  6. moved this from Todo to Has PR in Node-API Team Projecton Aug 1, 2025
  7. KevinEady commented on Aug 1, 2025

    @KevinEady
    ContributorAuthor

    @KevinEady to check if #1676 fixes the above crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions