Repository navigation
Open
Description
Version
v26.10.0
Platform
Linux 12cc91c12230 7.0.14-linuxkit #1 SMP PREEMPT Sun Sep 20 16:14:09 UTC 2026 aarch64 GNU/Linux
Subsystem
napi
What steps will reproduce the bug?
ext.c:
#include <assert.h>
#include <node_api.h>
#include <stdlib.h>
static void fin(node_api_basic_env env, void* data, void* hint) {
free(data);
}
static napi_value make(napi_env env, napi_callback_info info) {
napi_value out;
assert(node_api_create_external_string_latin1(env, calloc(1, 1 << 20), 1 << 20, fin, NULL, &out, NULL) == napi_ok);
return out;
}
NAPI_MODULE_INIT() {
napi_value fn;
assert(napi_create_function(env, "make", NAPI_AUTO_LENGTH, make, NULL, &fn) == napi_ok);
assert(napi_set_named_property(env, exports, "make", fn) == napi_ok);
return exports;
}run.cjs
const { make } = require("./ext.node");
for (let i = 0; i < 200; i++) make();
gc();$ clang -shared -fPIC -DNAPI_VERSION=10 -I/workspace/build/_deps/node_headers-src/include/node ext.c -o ext.node
$ node --expose-gc run.cjs
FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
----- Native stack trace -----
1: 0xaaaacea819c4 node::DumpNativeBacktrace(_IO_FILE*) [node]
2: 0xaaaacec15ca4 [node]
3: 0xaaaacec16d28 node::OnFatalError(char const*, char const*) [node]
4: 0xaaaacf11c250 [node]
5: 0xaaaace992a10 v8::HandleScope::Initialize(v8::Isolate*) [node]
6: 0xaaaace992994 v8::HandleScope::HandleScope(v8::Isolate*) [node]
7: 0xaaaaceb7c92c void node_napi_env__::CallFinalizer<true>(void (*)(napi_env__*, void*, void*), void*, void*) [node]
8: 0xaaaaceb74fe4 node_napi_env__::CallFinalizer(void (*)(napi_env__*, void*, void*), void*, void*) [node]
9: 0xaaaaceb3400c v8impl::Finalizer::CallFinalizer() [node]
10: 0xaaaaceb329a0 [node]
11: 0xaaaaceb44944 [node]
12: 0xaaaaceb44980 [node]
13: 0xaaaacf6c1cb0 [node]
14: 0xaaaacf668c18 [node]
15: 0xaaaacf658a80 [node]
16: 0xaaaad10fbac0 [node]
17: 0xaaaaced44554 [node]
18: 0xffffa3f39988 [/usr/lib/aarch64-linux-gnu/libc.so.6]
19: 0xffffa3fa1f1c [/usr/lib/aarch64-linux-gnu/libc.so.6]
FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
----- Native stack trace -----
1: 0xaaaacea819c4 node::DumpNativeBacktrace(_IO_FILE*) [node]
2: 0xaaaacec15ca4 [node]
3: 0xaaaacec16d28 node::OnFatalError(char const*, char const*) [node]
4: 0xaaaacf11c250 [node]
5: 0xaaaacf121b8c v8::EscapableHandleScopeBase::EscapableHandleScopeBase(v8::Isolate*) [node]
6: 0xaaaace9bdb2c v8::EscapableHandleScope::EscapableHandleScope(v8::Isolate*) [node]
7: 0xaaaacec14e90 node::GetCurrentStackTrace(v8::Isolate*, int) [node]
8: 0xaaaacea81abc node::DumpJavaScriptBacktrace(_IO_FILE*) [node]
9: 0xaaaacec15cb4 [node]
10: 0xaaaacec16d28 node::OnFatalError(char const*, char const*) [node]
11: 0xaaaacf11c250 [node]
12: 0xaaaace992a10 v8::HandleScope::Initialize(v8::Isolate*) [node]
13: 0xaaaace992994 v8::HandleScope::HandleScope(v8::Isolate*) [node]
14: 0xaaaaceb7c92c void node_napi_env__::CallFinalizer<true>(void (*)(napi_env__*, void*, void*), void*, void*) [node]
15: 0xaaaaceb74fe4 node_napi_env__::CallFinalizer(void (*)(napi_env__*, void*, void*), void*, void*) [node]
16: 0xaaaaceb3400c v8impl::Finalizer::CallFinalizer() [node]
17: 0xaaaaceb329a0 [node]
18: 0xaaaaceb44944 [node]
19: 0xaaaaceb44980 [node]
20: 0xaaaacf6c1cb0 [node]
21: 0xaaaacf668c18 [node]
22: 0xaaaacf658a80 [node]
23: 0xaaaad10fbac0 [node]
24: 0xaaaaced44554 [node]
25: 0xffffa3f39988 [/usr/lib/aarch64-linux-gnu/libc.so.6]
26: 0xffffa3fa1f1c [/usr/lib/aarch64-linux-gnu/libc.so.6]
Aborted node --expose-gc run.cjs
How often does it reproduce? Is there a required condition?
It reproduces reliably.
What is the expected behavior? Why is that the expected behavior?
It should not crash.
What do you see instead?
It crashes.
Additional information
v8 v14.5 now disposes these strings in a worker thread. So when napi goes to create a HandleScope in the finalizer it hits the crash.
The original PR: #48339 includes only very basic tests which don't hit garbage collection at all.
Search: node_api_create_external_string_latin1, napi_create_string_utf16
Metadata
Metadata
Assignees
Labels
No labels
Activity
Externalized string optimization