Skip to content

[Bug] Native addons deriving from node::ObjectWrap abort during GC on Node 24.19.0 / 24.20.0 #53387

Closed

Description

@appdevopts

Preflight Checklist

Electron Version

42.11.0

What operating system(s) are you using?

macOS

Operating System Version

macOS 26.3.1

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

42.10.0

Does the issue also appear in Chromium / Google Chrome?

I don't know how to test

Expected Behavior

A native addon deriving from node::ObjectWrap should not abort the process when its wrapped JS object is garbage collected.

Actual Behavior

After upgrading to 42.11.0 the main process aborts with SIGABRT from inside a V8 first-pass weak callback. The crash happens on a worker_threads thread of the main process. Symbolized frames from the minidump:

libsystem_kernel      __pthread_kill
libsystem_c           abort
Electron Framework    node::Assert(node::AssertionInfo const&)                        node_errors.cc
Electron Framework    node::RemoveEnvironmentCleanupHook(v8::Isolate*, void (*)(void*), void*) + 220
better_sqlite3.node   Statement::~Statement() + 312
better_sqlite3.node   Statement::~Statement() + 12
Electron Framework    v8::internal::GlobalHandles::InvokeFirstPassWeakCallbacks()
Electron Framework    v8::internal::Heap::CollectGarbage(...)
Electron Framework    v8::internal::HeapAllocator::CollectGarbageAndRetryAllocation(...)
Electron Framework    v8::internal::HeapAllocator::AllocateRawSlowPath(...)
Electron Framework    v8::internal::Runtime_AllocateInYoungGeneration(...)
                      [JS frames]
Electron Framework    node::worker::MessagePort::OnMessage(...)
Electron Framework    node::worker::Worker::StartThread(...)

The addon is a fork of better-sqlite3; its Statement class derives from node::ObjectWrap. The destructor itself contains no Node API calls — the call to RemoveEnvironmentCleanupHook comes from the inlined node::ObjectWrap::~ObjectWrap().

We have not captured the process stderr, so we do not have the printed assertion text. In Node v24.19.0 the only CHECK in RemoveEnvironmentCleanupHook is CHECK_NOT_NULL(env) at src/api/hooks.cc:142.

Root cause

42.11.0 updated Node.js to v24.19.0 (#52634).

v24.19.0 backported nodejs/node#63642 (4b5eb7b72d, "src: add cleanup hooks to node::ObjectWrap"), which makes the node::ObjectWrap constructor and destructor call AddEnvironmentCleanupHook / RemoveEnvironmentCleanupHook. ObjectWrap is header-only, so this call is compiled into any addon built against these headers.

v24.19.0 does not include nodejs/node#63985 (1723773d41, "src: keep global list of addon-provided cleanup hooks"), which reworks RemoveEnvironmentCleanupHook to resolve the hook through a global registry instead of the current Environment. From that commit message:

This occasionally breaks down when RemoveEnvironmentCleanupHook() is called during garbage collection -- which would be an expected use case of the functionality, but one that has not been covered through our tests before 215027c8eded2e.

In v24.19.0 and v24.20.0, src/api/hooks.cc still has:

void RemoveEnvironmentCleanupHook(Isolate* isolate,
                                  CleanupHook fun,
                                  void* arg) {
  Environment* env = Environment::GetCurrent(isolate);
  CHECK_NOT_NULL(env);
  env->RemoveCleanupHook(fun, arg);
}

and Environment::GetCurrent(v8::Isolate*) in src/env-inl.h returns nullptr when isolate->InContext() is false, which is the case while V8 invokes first-pass weak callbacks.

Affected branches

Both Node v24.19.0 and v24.20.0 versions contain #63642 without #63985.

Upstream status (checked 2026-09-02)

So #63985 does not appear to be independently applicable: nodejs/node#65195 reports that it is what introduces the use-after-free that #65630 fixes.

Testcase Gist URL

No response

Additional Information

Filing this for visibility. Whether and how to address it before Node ships a fixed v24.x is entirely up to the Electron maintainers.

The crashing class derives from node::ObjectWrap, so the trigger is the ObjectWrap destructor path rather than anything specific to this addon — any addon rebuilt against 24.19.0+ headers should be affected.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    • Status
      🛠️ Fixed for Next Release

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions