You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Heap-snapshot worker is leaked when loading a snapshot fails (missing/invalid file) #2448
HeapSnapshotManager.#loadSnapshot creates a HeapSnapshotWorkerProxy (a live worker) before it reads the snapshot file, but the manager only ever disposes workers that are tracked in the #snapshots map:
// src/HeapSnapshotManager.tsasync #loadSnapshot(absolutePath,uid){constworkerProxy=new ...HeapSnapshotWorkerProxy(...);// spawns a workerconstloaderProxy=workerProxy.createLoader(uid, ...);constfileStream=fsSync.createReadStream(absolutePath,{...});forawait(constchunkoffileStream){// throws ENOENT for a missing/unreadable fileawaitloaderProxy.write(chunk);}awaitloaderProxy.close();constsnapshot=awaitsnapshotPromise;return{snapshot,worker: workerProxy};}
getSnapshot has no try/catch and only calls #snapshots.set(...) on success. So when a load fails, the worker is never added to #snapshots, and therefore neither dispose(filePath) nor disposeAll() (added in #2428 for context teardown) can ever reach it. The worker leaks for the life of the process — one worker per failed load.
verifyFilesSchema: ['filePath'] on the read tools only checks the path is inside the workspace roots; it does not verify the file exists or is a valid snapshot.
Reproduction
Call any of get_heapsnapshot_summary / get_heapsnapshot_details / get_heapsnapshot_class_nodes / get_heapsnapshot_retainers / get_heapsnapshot_retaining_paths / get_heapsnapshot_edges with a filePath that is inside a workspace root but does not exist (or is a truncated / non-heapsnapshot file).
The call fails, and the worker created for it is never disposed.
Repeat → workers accumulate.
A direct unit test that fails on main:
constdisposeSpy=sinon.spy(DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy.prototype,'dispose',);constmanager=newHeapSnapshotManager();awaitassert.rejects(manager.getSnapshot('/nonexistent/does-not-exist.heapsnapshot'));sinon.assert.calledOnce(disposeSpy);// 0 calls on main
Expectation
A failed snapshot load disposes its worker rather than leaking it.
Fix: wrap the load body in try/catch and workerProxy.dispose() before rethrowing. I have this plus the regression test passing locally and can open a PR.
Activity
fix(memory): dispose the heap-snapshot worker when loading fails
fix(memory): dispose the heap-snapshot worker when loading fails (Chr…