Skip to content

chore: prevent start and stop to run in parallel#4335

Merged
olavloite merged 1 commit intomainfrom
sync-maintainer-start-stop
Feb 6, 2026
Merged

chore: prevent start and stop to run in parallel#4335
olavloite merged 1 commit intomainfrom
sync-maintainer-start-stop

Conversation

@olavloite
Copy link
Collaborator

Synchronize the start() and stop() methods of the session maintainer to prevent them from running at the same time. That could cause a data race on the scheduled future that the start() method sets, and the stop() method reads.

Synchronize the start() and stop() methods of the session maintainer to prevent
them from running at the same time. That could cause a data race on the scheduled
future that the start() method sets, and the stop() method reads.
@olavloite olavloite requested review from a team as code owners February 6, 2026 09:43
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: spanner Issues related to the googleapis/java-spanner API. labels Feb 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @olavloite, 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 enhances the thread-safety of the session management logic by synchronizing the start() and stop() methods of the MultiplexedSessionMaintainer. This crucial change prevents race conditions that could occur when these methods attempt to access or modify the scheduledFuture concurrently, thereby ensuring the stability and reliability of session maintenance operations.

Highlights

  • Concurrency Control: The start() and stop() methods within the MultiplexedSessionMaintainer class have been made synchronized to prevent concurrent execution and potential data races on the scheduledFuture.
  • Access Modifier Update: The access modifier for both start() and stop() methods has been changed from package-private to private, restricting their visibility and usage to within the MultiplexedSessionMaintainer class itself.
Changelog
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java
    • Modified the start() method to be private synchronized.
    • Modified the stop() method to be private synchronized.
Activity
  • No human activity has been recorded on this pull request yet.
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 correctly addresses a potential data race by synchronizing the start() and stop() methods of the MultiplexedSessionMaintainer. This change ensures thread safety when these methods are called concurrently. I've added a suggestion to further improve the start() method by making it idempotent, which will prevent a potential resource leak where multiple maintenance tasks could be scheduled without canceling the old ones.

@olavloite olavloite merged commit d5d3975 into main Feb 6, 2026
33 checks passed
@olavloite olavloite deleted the sync-maintainer-start-stop branch February 6, 2026 10:19
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 googleapis/java-spanner API. size: xs Pull request size is extra small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants