From dc84c55baa732b56d36664ef58812c44ac607b9b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 26 Jun 2025 13:32:38 +0200 Subject: [PATCH 1/2] v8: fix missing callback in heap utils destroy This fixes the v8.getHeapSnapshot() calls not properly being destroyed. Pipeline calls would for example not properly end without the callback being in place. --- lib/internal/heap_utils.js | 3 ++- test/sequential/test-heapdump.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/internal/heap_utils.js b/lib/internal/heap_utils.js index 1b18f997f08a9b..d3e8cdf532cd88 100644 --- a/lib/internal/heap_utils.js +++ b/lib/internal/heap_utils.js @@ -53,11 +53,12 @@ class HeapSnapshotStream extends Readable { this[kHandle].readStart(); } - _destroy() { + _destroy(err, callback) { // Release the references on the handle so that // it can be garbage collected. this[kHandle][owner_symbol] = undefined; this[kHandle] = undefined; + callback(err); } [kUpdateTimer]() { diff --git a/test/sequential/test-heapdump.js b/test/sequential/test-heapdump.js index f9df88375ae596..dc629a6e04027b 100644 --- a/test/sequential/test-heapdump.js +++ b/test/sequential/test-heapdump.js @@ -10,6 +10,7 @@ if (!isMainThread) { const { writeHeapSnapshot, getHeapSnapshot } = require('v8'); const assert = require('assert'); const fs = require('fs'); +const { promises: { pipeline }, PassThrough } = require('stream'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); @@ -78,3 +79,15 @@ process.chdir(tmpdir.path); JSON.parse(data); })); } + +{ + const passthrough = new PassThrough(); + passthrough.on('data', common.mustCallAtLeast(()=> { + // Do nothing, just consume the data + }, 1)); + + pipeline( + getHeapSnapshot(), + passthrough, + ).then(common.mustCall()); +} From df175e22537e59350f81f20cafb4ecf7e3656556 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 26 Jun 2025 19:00:46 +0200 Subject: [PATCH 2/2] fixup! please linter --- test/sequential/test-heapdump.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/sequential/test-heapdump.js b/test/sequential/test-heapdump.js index dc629a6e04027b..013da83125313c 100644 --- a/test/sequential/test-heapdump.js +++ b/test/sequential/test-heapdump.js @@ -82,9 +82,7 @@ process.chdir(tmpdir.path); { const passthrough = new PassThrough(); - passthrough.on('data', common.mustCallAtLeast(()=> { - // Do nothing, just consume the data - }, 1)); + passthrough.on('data', common.mustCallAtLeast(1)); pipeline( getHeapSnapshot(),