Repository navigation
fix(inspector): defer full garbage collection for local sessions - #95
Merged
Merged
Conversation
Add asynchronous full collection for callback and promise sessions, including workers. Match Node connection errors and pending callback cleanup. Heap allocation sampling remains unsupported.
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In-process
node:inspectorsessions rejectHeapProfiler.collectGarbage, so applications cannot request a full collection from a main-thread or local-worker session. Posting with a callback before connecting also reports the connection error asynchronously, unlike Node.Change
Implement
HeapProfiler.enable,disable, and deferred fullcollectGarbage. A native event-loop task performs Bun's synchronous full collection after the posting JavaScript job unwinds, then resolves the request. This boundary also lets WeakRef targets lose the current-job keep-alive before collection. Successful callbacks receive(null, {}); disconnected pending requests receive Node'sERR_INSPECTOR_CLOSEDon the next tick. Posting before connection throws synchronously for both overloads.A worker session created with
connect()collects that worker's VM. Collection throughconnectToMainThread()remains explicitly unsupported, avoiding a misleading successful collection of the worker heap. Heap allocation sampling remains unsupported: it requires a real JavaScript allocation sampler in JSC.Validation
Built and tested on Linux x64 (release, no LTO). Node 24.21.0 is the callback/error oracle. The unpatched current-main build fails all seven new regression checks; two existing connection checks pass. The patched inspector-profiler file passes 52/52 tests, and the surrounding inspector suite passes 76/76. Tests cover callback timing, actual WeakRef collection with a strongly reachable control, local workers, promise sessions, and disconnect/reconnect behavior.
Measured test costs: inspector-profiler build-and-test command 0.765 seconds; surrounding inspector build-and-test command 1.016 seconds. Builtin TypeScript check passes in 4.421 seconds. Baseline build 195.994 seconds; first successful candidate build 200.900 seconds; subsequent type-only repair build 6.123 seconds. Scoped P2 branch review is clean. Repeated application-consumer qualification is tracked separately; this PR does not claim allocation-sampling support.
Upstream
Related: oven-sh#34719 provides broad inspector/CDP routing, including generic main-thread heap collection through the existing adapter. Its worker fallback and native scheduling boundary do not cover this change. This focused implementation is not a port of that PR. Upstream proposal: oven-sh#44549, covering deferred collection and local-worker sessions.