Skip to content

Conversation

@egonelbre
Copy link
Contributor

No description provided.

@egonelbre egonelbre requested review from a team as code owners November 21, 2025 17:43
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Nov 21, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @egonelbre, 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 a goroutine leak within the Spanner client's session management. By explicitly closing the multiplexedSessionReq channel when the session pool is shut down, it prevents goroutines from remaining active indefinitely, thereby improving resource cleanup and overall application stability.

Highlights

  • Goroutine Leak Fix: Addressed a goroutine leak in the createMultiplexedSession mechanism by ensuring the associated channel is properly closed during session pool shutdown.
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.

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

  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.

Copy link
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 aims to fix a goroutine leak by closing the multiplexedSessionReq channel when the session pool is closed. While this correctly terminates the consumer goroutine, the placement of the close() call introduces a critical race condition. Closing the channel after releasing the mutex can lead to a panic if another goroutine attempts to send a request concurrently with the pool closure. I've recommended moving the close() call to be within the mutex-protected block to ensure atomicity and prevent this potential panic.

@rahul2393 rahul2393 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 21, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 21, 2025
@rahul2393
Copy link
Contributor

@olavloite / @sakthivelmanii need help in one more approval to merge this one, please help

}
p.mu.Unlock()
p.hc.close()
close(p.multiplexedSessionReq)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change would get lost if we remove the entire sessionPool implementation (which is the intention). So it might be better to put this line of code in the Client#Close() function instead to make sure it is not unintentionally deleted. AFAICT, there are no tests that verify that this is actually closed, meaning that it would also not be caught by any tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the property that should be enforced is that all started goroutines are stopped. If the channels is left open and no one is using it, then it probably doesn't matter.

Using synctest seems a good fit for this. However, it does require Go 1.25 or 1.24 with GOEXPERIMENT=synctest. I wouldn't want to bump minimum language version requirement just for that... however the test could be put behind build tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a draft for that test, however it fails at the moment #13406. Need to diagnose the issue, might require some additional fixes.

Copy link
Contributor

Choose a reason for hiding this comment

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

SG. I didn't really realize that the entire multiplexed session implementation lives in the session pool, so my comment that this call should be moved to outside the pool does not really make any sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I managed to fix #13406 and it succeeds when this PR is merged. However, the mock server still leaks, which I excluded from the check.

@rahul2393 rahul2393 merged commit 1805e89 into googleapis:main Nov 25, 2025
9 of 10 checks passed
@egonelbre egonelbre deleted the fix-multiplexed-session-leak branch November 25, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants