Skip to content

Conversation

@cshamrick
Copy link
Contributor

Refactors SDKBuilder to use a single, shared OkHttpClient instance across its operations.

Previously:

  • The getAuthInterceptor method created a dedicated OkHttpClient which was never closed, leading to a resource leak.
  • Multiple OkHttpClient instances were created throughout the SDKBuilder's lifecycle, reducing efficiency.

This change:

  • Modifies getAuthInterceptor and getKASClient to accept and utilize a shared OkHttpClient instance.
  • Ensures all network operations within the builder leverage a single, managed client.
  • Fixes the resource leak in getAuthInterceptor by ensuring the shared client is properly closed with the SDK.
  • Improves overall resource utilization and performance by reusing connection and thread pools.

Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @cshamrick, 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 addresses resource management and efficiency within the SDK by refactoring the SDKBuilder to leverage a single, shared OkHttpClient instance. This change prevents resource leaks caused by unclosed client instances and enhances performance by consolidating network operations to a single, reusable client, thereby optimizing resource utilization across the SDK.

Highlights

  • Resource Leak Fix: The getAuthInterceptor method previously created an OkHttpClient instance that was never properly closed, leading to a resource leak. This has been resolved by ensuring a shared client is used and managed.
  • Efficiency Improvement: Multiple OkHttpClient instances were being created throughout the SDKBuilder's lifecycle. This change refactors the builder to use a single, shared OkHttpClient instance, improving efficiency by reusing connection and thread pools.
  • Shared OkHttpClient Instance: The getAuthInterceptor and getKASClient methods have been modified to accept and utilize a shared OkHttpClient instance, centralizing network operations within the builder.
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 is a valuable improvement, refactoring the SDK to use a single shared OkHttpClient instance. This correctly addresses a resource leak in getAuthInterceptor and improves overall efficiency by reusing connection and thread pools. My main feedback concerns a subtle lifecycle management issue introduced by this change. While the OkHttpClient is now correctly shared, the KASClient still attempts to manage its lifecycle in its close() method, leading to redundant shutdown operations. I've left a specific comment on how to address this to ensure clear ownership and prevent potential issues.

Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

@cshamrick
Copy link
Contributor Author

cshamrick commented Dec 8, 2025

@gemini-code-assist review

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 effectively addresses a resource leak and improves efficiency by refactoring the SDK to use a single, shared OkHttpClient instance. The changes correctly centralize the client's creation and lifecycle management within SDKBuilder, and propagate the shared client to getAuthInterceptor and getKASClient. The implementation is solid and achieves the stated goals. I have one minor suggestion for code cleanup.

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Dec 9, 2025

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2025

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

@cshamrick cshamrick marked this pull request as ready for review December 9, 2025 01:20
@cshamrick cshamrick requested review from a team as code owners December 9, 2025 01:20
@cshamrick cshamrick changed the title fix(sdk): Share OkHttpClient instance to prevent resource leaks fix(sdk): improve http client shutdown and resource management Dec 9, 2025
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.

2 participants