Skip to content

fix(core): add timeout to tree-sitter initialization to prevent hanging#24970

Closed
spencer426 wants to merge 1 commit intomainfrom
fix/shell-parser-timeout
Closed

fix(core): add timeout to tree-sitter initialization to prevent hanging#24970
spencer426 wants to merge 1 commit intomainfrom
fix/shell-parser-timeout

Conversation

@spencer426
Copy link
Copy Markdown
Contributor

@spencer426 spencer426 commented Apr 8, 2026

Summary

Addresses a memory leak where the Tree-Sitter loader Promise could hang indefinitely by adding a robust 30-second timeout and an explicit state variable.

Details

The treeSitterInitialization Promise in shell-utils.ts could hang indefinitely if the native WASM bindings failed to initialize, leaking the module execution context. The fix wraps it in an aggressive 30000ms Promise.race timeout that rejects safely on failure, uses an explicit state variable instead of relying on the Promise object, and properly clears the timeout on success via a .finally() block so it does not hang the process.

This is 3 of 4 atomic PRs split from the monolithic memory leak PR #24963.

Related Issues

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

@spencer426 spencer426 requested a review from a team as a code owner April 8, 2026 21:07
@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 improves the robustness of shell parser initialization and process execution. By implementing timeouts and explicit state tracking for Tree-Sitter, it prevents potential memory leaks and hangs. Additionally, it ensures reliable resource cleanup for spawned processes by wrapping execution logic in try...finally blocks.

Highlights

  • Tree-Sitter Initialization Timeout: Added a 30-second timeout to the Tree-Sitter initialization process using Promise.race to prevent indefinite hanging if native WASM bindings fail.
  • Parser State Management: Introduced an explicit parserState variable to track initialization progress, replacing reliance on the Promise object itself.
  • Resource Cleanup: Wrapped spawnAsync and execStreaming operations in try...finally blocks to ensure that prepared resources are properly cleaned up regardless of execution outcome.
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
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Apr 8, 2026

Hi @spencer426, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

You already have 7 pull requests open. Please work on getting existing PRs merged before opening more.

@github-actions github-actions Bot closed this Apr 8, 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 enhances the shell utility functions by introducing a state machine and a 30-second timeout to the shell parser initialization process to prevent hangs. Additionally, it ensures that cleanup logic is consistently executed in both spawnAsync and execStreaming by wrapping the core execution logic in try...finally blocks. I have no feedback to provide.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant