-
Notifications
You must be signed in to change notification settings - Fork 67
s2a: use AdvancedTls. #4004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
s2a: use AdvancedTls. #4004
Conversation
Summary of ChangesHello @rmehta19, 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 refactors the S2A (Secure Session Access) channel credential provisioning within the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 updates the S2A channel credential creation to use AdvancedTlsX509KeyManager and AdvancedTlsX509TrustManager, which enables automatic reloading of credentials. The change is functionally correct for enabling this feature. However, I've identified a critical resource leak where ScheduledExecutorService instances are created but never shut down, which could lead to an accumulation of threads over time. My review includes a comment detailing this issue and a recommendation for how to resolve it.
| ScheduledExecutorService keyManagerExecutor = Executors.newSingleThreadScheduledExecutor( | ||
| r -> { | ||
| Thread t = new Thread(r, "s2a-key-manager-updater"); | ||
| t.setDaemon(true); | ||
| return t; | ||
| }); | ||
|
|
||
| keyManager.updateIdentityCredentials(certChain, privateKey, 1, TimeUnit.HOURS, keyManagerExecutor); | ||
| AdvancedTlsX509TrustManager trustManager = AdvancedTlsX509TrustManager.newBuilder().build(); | ||
| ScheduledExecutorService trustManagerExecutor = Executors.newSingleThreadScheduledExecutor( | ||
| r -> { | ||
| Thread t = new Thread(r, "s2a-trust-manager-updater"); | ||
| t.setDaemon(true); | ||
| return t; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating new ScheduledExecutorService instances within createMtlsToS2AChannelCredentials on each call will lead to a resource leak. This method may be called multiple times during the lifetime of a client (e.g., for each channel in a pool, and when channels are refreshed), but the created executors are never shut down. This will cause threads to accumulate over time.
To fix this, you should use shared ScheduledExecutorService instances. A recommended approach is to define them as static final fields in the InstantiatingGrpcChannelProvider class and reuse them here. Since the threads are already configured as daemons, they won't block JVM exit, but sharing them is crucial to prevent resource leaks within a long-running application.
Additionally, the logic for creating the executors is duplicated. You could extract it into a helper method. You might also consider if a single shared executor is sufficient for both the key manager and the trust manager, which would further reduce resource usage.
Thank you for opening a Pull Request! Before submitting your PR, please read our contributing guidelines.
There are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️