24.19.0: `node::ObjectWrap` cleanup hooks backported without the cleanup hook registry, aborts on every 24.x runtime
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Beginne mit src/node_object_wrap.h und src/api/hooks.cc und reproduziere dann die Header-/Runtime-Matrix mithilfe des bereitgestellten addon.cc- und index.js-Allokationsloops. Vergleiche den Zustand von 24.x mit dem Commit 1723773d und den zugehörigen Änderungen in #63642. Erledigt ist die Aufgabe, wenn ein mit 24.19.0 erstelltes ObjectWrap-Addon die durch Allokationen ausgelöste Sammlung auf der 24.19.0-Runtime ohne die cleanup-hook-Assertion übersteht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Version
v24.19.0 (also affects v24.x-staging)
Platform
Reproduced on: Darwin 25.5.0 arm64 (official darwin-arm64 tarballs)
Originally hit on: Linux x86_64, Debian 13 container
Subsystem
src, addons
What steps will reproduce the bug?
This is the 24.x counterpart of #65262, but with an important difference: on the 24.x line
the crash does not need a header/runtime version mismatch. Headers and runtime both at
24.19.0 abort deterministically.
addon.cc (same minimal reproducer as #65262):
#include <node.h>
#include <node_object_wrap.h>
using namespace v8;
class Thing : public node::ObjectWrap {
public:
static void New(const FunctionCallbackInfo<Value>& args) {
(new Thing())->Wrap(args.This());
}
};
void Init(Local<Object> exports) {
Isolate* isolate = Isolate::GetCurrent();
Local<Context> context = isolate->GetCurrentContext();
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, Thing::New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
exports->Set(context,
String::NewFromUtf8(isolate, "Thing").ToLocalChecked(),
tpl->GetFunction(context).ToLocalChecked()).Check();
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
index.js:
const { Thing } = require(process.argv[2]);
let junk = [];
for (let i = 0; i < 300000; i++) {
new Thing(); // wrapped object, immediately unreachable
junk.push({ a: i }); // keep allocation rate high so V8 collects on its own
if (junk.length > 1000) junk = [];
}
console.log('survived');
Build against each header set and run each binary on each runtime:
for V in 24.18.1 24.19.0; do
curl -sfLO "https://nodejs.org/dist/v$V/node-v$V-darwin-arm64.tar.gz"
tar -xzf "node-v$V-darwin-arm64.tar.gz"
clang++ -std=c++20 -fPIC -shared -Wl,-undefined,dynamic_lookup \
-I"node-v$V-darwin-arm64/include/node" \
-DNODE_GYP_MODULE_NAME=addon -o "addon-hdr-$V.node" addon.cc
done
for HV in 24.18.1 24.19.0; do
for RV in 24.18.1 24.19.0; do
./node-v$RV-darwin-arm64/bin/node index.js "./addon-hdr-$HV.node"
echo "hdr $HV / rt $RV -> rc=$?"
done
done
How often does it reproduce? Is there a required condition?
Deterministic, 5/5 runs for both crashing combinations.
| hdr \ rt | 24.18.1 | 24.19.0 |
|---|---|---|
| 24.18.1 | ok | ok |
| 24.19.0 | crash | crash |
Compare with the 26.x matrix in #65262, where headers 26.4.0 on runtime 26.4.0 is fine.
As in that issue, an explicit global.gc() does not trigger it; the collection has to be
allocation driven.
What is the expected behavior? Why is that the expected behavior?
An addon that uses node::ObjectWrap and is built against 24.19.0 headers should keep
working on a 24.19.0 runtime. Today there is no 24.x runtime it works on.
What do you see instead?
# node[52504]: void node::RemoveEnvironmentCleanupHook(Isolate *, CleanupHook, void *) at ../src/api/hooks.cc:142
# Assertion failed: (env) != nullptr
1: node::Assert(node::AssertionInfo const&) [node]
2: node::RemoveEnvironmentCleanupHook(v8::Isolate*, void (*)(void*), void*) (.cold.1) [node]
4: node::ObjectWrap::RemoveCleanupHook() [addon-hdr-24.19.0.node]
5: node::ObjectWrap::~ObjectWrap() [addon-hdr-24.19.0.node]
Additional information
The cause looks like a partial backport. 24.19.0 picked up src: add cleanup hooks to node::ObjectWrap (#63642), which adds AddCleanupHook() to the constructor and
RemoveCleanupHook() to the destructor of the header only node::ObjectWrap class. It did
not pick up 1723773d4133fc71215a9cbb7e2b9a2a11fc3688 (src: keep global list of addon-provided cleanup hooks), which is what makes hook removal survive without a live
Environment and which is why the 26.x matrix in #65262 has a working diagonal.
$ curl -s https://raw.githubusercontent.com/nodejs/node/v24.19.0/src/node_object_wrap.h | grep -c 'RemoveCleanupHook()'
2
$ curl -s https://raw.githubusercontent.com/nodejs/node/v24.19.0/src/api/hooks.cc | grep -c CleanupHookThunk
0
$ curl -s https://raw.githubusercontent.com/nodejs/node/v26.4.0/src/api/hooks.cc | grep -c CleanupHookThunk
6
v24.x-staging is currently in the same state, and v24.19.0 is the newest v24 tag, so
every published 24.x runtime is affected once an addon is compiled with 24.19.0 headers.
Because node_object_wrap.h is header only, this reaches users who never changed a
dependency: rebuilding a container image after 2026-08-03 is enough, since the new
destructor code gets compiled into the addon. It hits NAN style addons in particular,
because they commonly do using namespace node; and inherit from node::ObjectWrap.
Real world example that led me here: a long running service in a Docker image, no
dependency version changed, only the Node base image moved 24.18.0 -> 24.19.0. The process
started aborting during periodic SFTP transfers, when the garbage collector reclaimed one
of ssh2's native cipher objects:
# node[7]: void node::RemoveEnvironmentCleanupHook(v8::Isolate*, CleanupHook, void*) at ../../src/api/hooks.cc:142
# Assertion failed: (env) != nullptr
1: node::Assert(node::AssertionInfo const&) [node]
2: node::RemoveEnvironmentCleanupHook(v8::Isolate*, void (*)(void*), void*) [node]
3: AESGCMDecipher::~AESGCMDecipher() [<app>/node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node]
Downstream reports of the same assertion with other NAN style addons (better-sqlite3,
node-pty) after the same base image move: nexu-io/open-design#6462.
Possible ways out, in order of preference from a user point of view:
- Backport
1723773dtov24.x-stagingsoRemoveEnvironmentCleanupHookno longer needs
a liveEnvironment. - Or revert #63642 on the 24.x line until 1 is done.
Refs: #63642 #65262 #65195
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.4k
- Ø Merge
- 4 T. 3 Std.
- Gemergte PRs (30 T.)
- 279
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nodejs/node
-
doc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
build
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
feature request
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Ähnliche Issues
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Improve Title Support Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·