Skip to content

fix(core): resolve MCP process leaks, deadlocks, and config regressions Fix #23344#23363

Closed
PrajwaL-N-TECHIE wants to merge 3 commits intogoogle-gemini:mainfrom
PrajwaL-N-TECHIE:fix/process-leaks-and-excludes
Closed

fix(core): resolve MCP process leaks, deadlocks, and config regressions Fix #23344#23363
PrajwaL-N-TECHIE wants to merge 3 commits intogoogle-gemini:mainfrom
PrajwaL-N-TECHIE:fix/process-leaks-and-excludes

Conversation

@PrajwaL-N-TECHIE
Copy link
Copy Markdown

This PR addresses multiple high-impact bugs:

  1. MCP processes hanging during shutdown (fixed with timeouts and hard-kills).
  2. Configuration regression for custom excludes (implemented getCustomExcludes).
  3. Redundant telemetry signal handlers (removed).

Fixes #23344

Summary

Details

Related Issues

How to Validate

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

This PR addresses multiple high-impact bugs:
1. MCP processes hanging during shutdown (fixed with timeouts and hard-kills).
2. Configuration regression for custom excludes (implemented getCustomExcludes).
3. Redundant telemetry signal handlers (removed).

Fixes google-gemini#23344
@PrajwaL-N-TECHIE PrajwaL-N-TECHIE requested review from a team as code owners March 21, 2026 10:05
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 resolves critical bugs related to MCP process management, configuration handling, and telemetry within the Gemini CLI. It introduces process timeouts and hard-kills to prevent MCP processes from hanging during shutdown, corrects a regression in custom file exclusion configurations, and optimizes telemetry signal handling.

Highlights

  • MCP Process Management: Addresses MCP process leaks during shutdown by implementing timeouts and hard-kills to prevent hanging processes.
  • Configuration Regression: Fixes a configuration regression for custom excludes by implementing getCustomExcludes to properly handle user-defined file exclusions.
  • Telemetry Signal Handlers: Removes redundant telemetry signal handlers to streamline the telemetry shutdown process.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 21, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request focuses on fixes for MCP process management, including addressing process leaks and deadlocks during shutdown. A critical security vulnerability has been identified: the MCP client's SSE fallback logic is susceptible to OAuth token leakage due to incorrect server name usage, potentially allowing malicious endpoints to steal credentials. Additionally, the pull request includes fixes for custom excludes configuration and redundant telemetry handlers. Consider improving type safety when accessing internal SDK properties to align with repository best practices.

Comment on lines +1946 to +1950
const result = await connectWithSSETransport(
mcpClient,
mcpServerConfig,
await getStoredOAuthToken(mcpServerName),
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The tool's SSE fallback logic retrieves a stored OAuth token using only the MCP server name as a key and transmits it to the URL specified in the server's configuration. This mechanism is vulnerable to token leakage if an attacker can provide a malicious MCP server configuration that uses the same name as a trusted server but a different URL. By causing the initial connection to fail, the attacker can force the tool to fall back to SSE and send the trusted server's sensitive OAuth token to an attacker-controlled endpoint.

Remediation:
Modify the token retrieval and transmission logic to ensure that OAuth tokens are only sent to the specific URL(s) for which they were issued. Key the token storage by both the server name and its base URL, and validate the destination URL before including the Authorization header in the request.

Comment on lines +178 to +193
getPid(): number | undefined {
let t = this.transport;
if (t instanceof XcodeMcpBridgeFixTransport) {
// Access the internal transport which is not exposed in the FixTransport type.
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-type-assertion */
t = (t as any).transport;
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-type-assertion */
}
if (t instanceof StdioClientTransport) {
// StdioClientTransport has a process property at runtime but it's not in the public types.
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
return (t as any).process?.pid;
/* eslint-enable @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
}
return undefined;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To improve type safety and maintainability when accessing internal properties of SDK objects, it's better to avoid casting to any and disabling ESLint rules. As per repository rules for handling undocumented properties, if such usage is unavoidable, a local interface should be defined for these properties, and a detailed comment explaining the rationale and why a public API could not be used must be added. The provided suggestion uses a more constrained type assertion (as unknown as { property: Type }), which is an improvement, but ensure the rationale for accessing internal properties is clearly documented.

  getPid(): number | undefined {
    let t = this.transport;
    if (t instanceof XcodeMcpBridgeFixTransport) {
      // Access the internal transport which is not exposed in the FixTransport type.
      t = (t as unknown as { transport: Transport }).transport;
    }
    if (t instanceof StdioClientTransport) {
      // StdioClientTransport has a process property at runtime but it's not in the public types.
      return (t as unknown as { process?: { pid?: number } }).process?.pid;
    }
    return undefined;
  }
References
  1. The current implementation uses as any to access internal SDK properties. The repository rule states that if using internal or undocumented SDK properties is unavoidable, a local interface should be defined for them, and a detailed comment explaining the rationale should be added.

This commit addresses PR feedback:
1. Security: OAuth tokens are now keyed and validated by both server name and URL to prevent leakage during SSE fallback.
2. Type Safety: Refactored McpClient.getPid() to use recommended 'as unknown as' type assertions instead of disabling ESLint rules.
3. Quality: Added File global polyfill to test-setup.ts to fix undici environment issues in Vitest.
4. Testing: Updated hybrid-token-storage tests to match new 2-argument signatures.
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Apr 5, 2026

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Severe process leak and hanging (Deadlock) when running multiple instances

1 participant