fix: handle inspector session leak on Profiler.enable/start failure#63290
Closed
buley wants to merge 1 commit intomicrosoft:mainfrom
Closed
fix: handle inspector session leak on Profiler.enable/start failure#63290buley wants to merge 1 commit intomicrosoft:mainfrom
buley wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a resource leak in the Node.js CPU profiler integration by ensuring an inspector.Session is disconnected when Profiler.enable or Profiler.start fails, preventing a connected session from lingering until process exit.
Changes:
- Handle the
errparameter insession.post("Profiler.enable", ...)and disconnect on failure. - Handle the
errparameter insession.post("Profiler.start", ...)and disconnect on failure. - Ensure the continuation callback is still invoked on error so the caller proceeds.
Collaborator
|
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
This was referenced Mar 24, 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.
Summary
enableCPUProfilerinsrc/compiler/sys.tscallssession.connect()but the callbacks forProfiler.enableandProfiler.startignore the error parameter. If either V8 API call fails, the inspector session is never disconnected.Bug verification
session.connect()is called at line 1657session.post("Profiler.enable", callback)-- callback signature is(err, result)buterris ignoredProfiler.enablefails (e.g., profiler already active),activeSessionis never setdisableCPUProfilerchecksactiveSessionbefore callingsession.disconnect()-- it will never find the leaked sessionFix
Add error parameters to both callbacks. On failure, disconnect the session immediately and invoke the continuation callback so the caller is not left hanging.
Found by Gnosis Polyglot Scanner, an open-source static analysis tool that detects resource leaks across languages via topological analysis of control flow graphs.
Signed-off-by: Taylor Buley taylor@forkjoin.ai