From c93c13902c4becd52afb54b694352589b4311667 Mon Sep 17 00:00:00 2001 From: bailey Date: Tue, 28 Oct 2025 14:30:44 -0600 Subject: [PATCH 1/3] remove dependency on heapsnapshot --- .../node-specific/resource_clean_up.test.ts | 15 ++++----------- .../resource_tracking_script_builder.ts | 12 +++++------- test/tools/fixtures/heap_resource_script.in.js | 13 +++++++++---- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/test/integration/node-specific/resource_clean_up.test.ts b/test/integration/node-specific/resource_clean_up.test.ts index 4fd1bd53b1e..edcb7e48fc2 100644 --- a/test/integration/node-specific/resource_clean_up.test.ts +++ b/test/integration/node-specific/resource_clean_up.test.ts @@ -17,7 +17,7 @@ const MB_PERMITTED_OFFSET = 5; describe('Driver Resources', () => { let startingMemoryUsed; let endingMemoryUsed; - let heap; + let clientsInMemory; beforeEach(function () { if (globalThis.AbortController == null) { @@ -34,12 +34,6 @@ describe('Driver Resources', () => { context('on MongoClient.close()', () => { before('create leak reproduction script', async function () { - if (process.version.includes('v24')) { - if (this.test) { - this.test.skipReason = 'TODO(NODE-6945): Fix v24 heap snapshot parsing'; - } - this.test?.skip(); - } if (globalThis.AbortController == null || typeof this.configuration.serverApi === 'string') { return; } @@ -58,7 +52,7 @@ describe('Driver Resources', () => { startingMemoryUsed = res.startingMemoryUsed; endingMemoryUsed = res.endingMemoryUsed; - heap = res.heap; + clientsInMemory = res.clientsInMemory; }); describe('ending memory usage', () => { @@ -77,11 +71,10 @@ describe('Driver Resources', () => { describe('ending heap snapshot', () => { it('has 0 MongoClients in memory', async () => { - const clients = heap.nodes.filter(n => n.name === 'MongoClient' && n.type === 'object'); // lengthOf crashes chai b/c it tries to print out a gigantic diff expect( - clients.length, - `expected no MongoClients in the heapsnapshot, found ${clients.length}` + clientsInMemory, + `expected no MongoClients in the heapsnapshot, found ${clientsInMemory}` ).to.equal(0); }); }); diff --git a/test/integration/node-specific/resource_tracking_script_builder.ts b/test/integration/node-specific/resource_tracking_script_builder.ts index e166dfb6b4c..7839b784b87 100644 --- a/test/integration/node-specific/resource_tracking_script_builder.ts +++ b/test/integration/node-specific/resource_tracking_script_builder.ts @@ -106,7 +106,6 @@ export async function runScriptAndReturnHeapInfo( }; log('starting'); const scriptName = `${name}.cjs`; - const heapsnapshotFile = `${name}.heapsnapshot.json`; const scriptContent = await testScriptFactory( name, @@ -148,6 +147,10 @@ export async function runScriptAndReturnHeapInfo( const startingMemoryUsed = starting.value[0].startingMemoryUsed; const endingMemoryUsed = ending.value[0].endingMemoryUsed; + const { + value: [{ clientsInMemory }] + } = await messages.next(); + // make sure the process ended const [exitCode] = await willClose; @@ -155,21 +158,16 @@ export async function runScriptAndReturnHeapInfo( expect(exitCode, 'process should have exited with zero').to.equal(0); - const heap = await readFile(heapsnapshotFile, { encoding: 'utf8' }).then(c => - parseSnapshot(JSON.parse(c)) - ); - log('done.'); // If any of the above throws we won't reach these unlinks that clean up the created files. // This is intentional so that when debugging the file will still be present to check it for errors await unlink(scriptName); - await unlink(heapsnapshotFile); return { startingMemoryUsed, endingMemoryUsed, - heap + clientsInMemory }; } diff --git a/test/tools/fixtures/heap_resource_script.in.js b/test/tools/fixtures/heap_resource_script.in.js index afe7407fcb0..986f36ff2a8 100644 --- a/test/tools/fixtures/heap_resource_script.in.js +++ b/test/tools/fixtures/heap_resource_script.in.js @@ -59,11 +59,16 @@ async function main() { process.send({ endingMemoryUsed }); log('second message sent.'); - const start = now(); - v8.writeHeapSnapshot(`${name}.heapsnapshot.json`); - const end = now(); + const clientsInMemory = v8.queryObjects(MongoClient); - log(`heap snapshot written in ${end - start}ms. script exiting`); + process.send({ clientsInMemory }); + + log('clients instances in memory sent.'); + // const start = now(); + // v8.writeHeapSnapshot(`${name}.heapsnapshot.json`); + // const end = now(); + + // log(`heap snapshot written in ${end - start}ms. script exiting`); } main() From 77f4873bf5650762fbd8a3c141121e7b8b4f910b Mon Sep 17 00:00:00 2001 From: bailey Date: Wed, 29 Oct 2025 10:25:01 -0600 Subject: [PATCH 2/3] misc cleanups --- .../node-specific/resource_tracking_script_builder.ts | 8 ++++++-- test/tools/fixtures/heap_resource_script.in.js | 5 ----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/integration/node-specific/resource_tracking_script_builder.ts b/test/integration/node-specific/resource_tracking_script_builder.ts index 7839b784b87..0b070550d6d 100644 --- a/test/integration/node-specific/resource_tracking_script_builder.ts +++ b/test/integration/node-specific/resource_tracking_script_builder.ts @@ -144,8 +144,12 @@ export async function runScriptAndReturnHeapInfo( log('fetching messages 3: ', ending); - const startingMemoryUsed = starting.value[0].startingMemoryUsed; - const endingMemoryUsed = ending.value[0].endingMemoryUsed; + const { + value: [{ startingMemoryUsed }] + } = starting; + const { + value: [{ endingMemoryUsed }] + } = ending; const { value: [{ clientsInMemory }] diff --git a/test/tools/fixtures/heap_resource_script.in.js b/test/tools/fixtures/heap_resource_script.in.js index 986f36ff2a8..3936a967281 100644 --- a/test/tools/fixtures/heap_resource_script.in.js +++ b/test/tools/fixtures/heap_resource_script.in.js @@ -64,11 +64,6 @@ async function main() { process.send({ clientsInMemory }); log('clients instances in memory sent.'); - // const start = now(); - // v8.writeHeapSnapshot(`${name}.heapsnapshot.json`); - // const end = now(); - - // log(`heap snapshot written in ${end - start}ms. script exiting`); } main() From e356d758e2ee11922d0d96ae57b5d622c7d99f9b Mon Sep 17 00:00:00 2001 From: bailey Date: Thu, 30 Oct 2025 09:31:48 -0600 Subject: [PATCH 3/3] fix lint --- .../node-specific/resource_tracking_script_builder.ts | 1 - test/tools/fixtures/heap_resource_script.in.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/test/integration/node-specific/resource_tracking_script_builder.ts b/test/integration/node-specific/resource_tracking_script_builder.ts index 0b070550d6d..f4160d8e539 100644 --- a/test/integration/node-specific/resource_tracking_script_builder.ts +++ b/test/integration/node-specific/resource_tracking_script_builder.ts @@ -7,7 +7,6 @@ import { inspect } from 'node:util'; import { AssertionError, expect } from 'chai'; import type * as timers from 'timers'; -import { parseSnapshot } from 'v8-heapsnapshot'; import type * as mongodb from '../../mongodb'; import { type MongoClient } from '../../mongodb'; diff --git a/test/tools/fixtures/heap_resource_script.in.js b/test/tools/fixtures/heap_resource_script.in.js index 3936a967281..690214168d9 100644 --- a/test/tools/fixtures/heap_resource_script.in.js +++ b/test/tools/fixtures/heap_resource_script.in.js @@ -4,7 +4,6 @@ const driverPath = DRIVER_SOURCE_PATH; const func = FUNCTION_STRING; -const name = SCRIPT_NAME_STRING; const uri = URI_STRING; const iterations = ITERATIONS_STRING; const { inspect } = require('util'); @@ -15,7 +14,6 @@ const v8 = require('node:v8'); const util = require('node:util'); const timers = require('node:timers'); -const now = performance.now.bind(performance); const sleep = util.promisify(timers.setTimeout); const run = func;