fix(patch): cherry-pick 9590a09 to release/v0.29.0-preview.4-pr-18771 to patch version v0.29.0-preview.4 and create version 0.29.0-preview.5#19274
Conversation
Summary of ChangesHello @gemini-cli-robot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request automates the cherry-picking of a specific commit to create a new patch version for a preview release. The primary technical change involves streamlining the MCP client connection process by refactoring the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Size Change: -810 B (0%) Total Size: 23.9 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
The pull request refactors the MCP connection logic to return only the Client instance instead of a { client, transport } object. While this simplifies the API, it introduces resource leaks in the onerror handlers because the explicit transport closing logic was removed but not replaced with client.close(). Additionally, the McpClient class now contains dead code and an uninitialized transport property that breaks its internal cleanup logic.
| this.client = await connectToMcpServer( | ||
| this.clientVersion, | ||
| this.serverName, | ||
| this.serverConfig, | ||
| this.debugMode, | ||
| this.workspaceContext, | ||
| this.cliConfig.sanitizationConfig, | ||
| ); |
There was a problem hiding this comment.
The removal of the this.transport = transport assignment leaves the transport property of the McpClient class (defined at line 112) permanently uninitialized. This breaks the cleanup logic in the disconnect() method (lines 213-215), which still attempts to close this.transport. Since connectToMcpServer now only returns the Client instance, the direct reference to the transport is lost. To maintain correctness, the transport property should be removed from the class, and the disconnect() method should be updated to rely solely on this.client.close() (which internally closes the transport).
| mcpClient.onerror = (error) => { | ||
| coreEvents.emitFeedback('error', `MCP ERROR (${mcpServerName}):`, error); | ||
| updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED); | ||
| // Close transport to prevent memory leaks | ||
| if (transport) { | ||
| try { | ||
| await transport.close(); | ||
| } catch { | ||
| // Ignore errors when closing transport on error | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
Similar to the McpClient class, the onerror handler in connectAndDiscover no longer performs cleanup. While the catch block at the end of the function handles errors during the discovery process, an asynchronous error triggered via onerror should also ensure the client is closed to prevent leaking resources like subprocesses or network connections.
| mcpClient.onerror = (error) => { | |
| coreEvents.emitFeedback('error', `MCP ERROR (${mcpServerName}):`, error); | |
| updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED); | |
| // Close transport to prevent memory leaks | |
| if (transport) { | |
| try { | |
| await transport.close(); | |
| } catch { | |
| // Ignore errors when closing transport on error | |
| } | |
| } | |
| }; | |
| mcpClient.onerror = (error) => { | |
| coreEvents.emitFeedback('error', `MCP ERROR (${mcpServerName}):`, error); | |
| updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED); | |
| mcpClient?.close().catch(() => {}); | |
| }; |
b3ac129
into
release/v0.29.0-preview.4-pr-18771
This PR automatically cherry-picks commit 9590a09 to patch version v0.29.0-preview.4 in the preview release to create version 0.29.0-preview.5.