Skip to content

fix(go): prevent goroutine leak on tool error#5483

Open
arthu-rguo wants to merge 1 commit into
genkit-ai:mainfrom
arthu-rguo:fix/tool-err-goroutine-leak
Open

fix(go): prevent goroutine leak on tool error#5483
arthu-rguo wants to merge 1 commit into
genkit-ai:mainfrom
arthu-rguo:fix/tool-err-goroutine-leak

Conversation

@arthu-rguo

Copy link
Copy Markdown

explanation:

  • The handleToolRequests helper in generate.go spawns a worker goroutine for each tool request.
  • The worker goroutines send the tool results to an unbuffered channel.
  • If any tool errors out, the receiver exits without draining the channel and all remaining worker goroutines are permanently blocked on the send.

fix:

  • Buffer the channel so all worker goroutines can send and exit.
  • Add a regression test.

Checklist (if applicable):

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

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.

Code Review

This pull request buffers the resultChan channel in handleToolRequests to prevent goroutine leaks when handling tool requests, and adds a corresponding unit test TestGenerateNoGoroutineLeak to verify this behavior. The reviewer pointed out that a similar goroutine leak pattern exists in handleResumeOption where resultChan is also unbuffered, and suggested buffering it there as well.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread go/ai/generate.go
@arthu-rguo arthu-rguo force-pushed the fix/tool-err-goroutine-leak branch from cfa654b to 62389c7 Compare June 6, 2026 07:46
@arthu-rguo

Copy link
Copy Markdown
Author

/gemini review

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

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.

Code Review

This pull request addresses potential goroutine leaks in go/ai/generate.go by buffering the resultChan channels in both handleToolRequests and handleResumeOption to match the number of tool requests. This ensures that goroutines executing tools do not block indefinitely if the main routine exits early due to an error. Additionally, a new test TestGenerateNoGoroutineLeak has been added to verify this behavior. There are no review comments to address, and the changes look solid.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants