Skip to content

Add Ready() to jwks.Remote#251

Merged
rthellend merged 3 commits intomainfrom
jwks-ready
Jan 30, 2026
Merged

Add Ready() to jwks.Remote#251
rthellend merged 3 commits intomainfrom
jwks-ready

Conversation

@rthellend
Copy link
Collaborator

Description

Add Ready() to jwks.Remote. This function returns when all issuer keys have been fetched at least once.

Type of change

  • New feature
  • Feature improvement
  • Bug fix
  • Documentation
  • Cleanup / refactoring
  • Other (please explain)

How is this change tested ?

  • Unit tests
  • Manual tests (explain)
  • Tests are not needed

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rthellend, 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 introduces a Ready() method to the jwks.Remote component, providing a standardized and efficient way to determine when all configured JSON Web Key Set (JWKS) issuer keys have completed their initial fetch. This enhancement improves the reliability of services that depend on these keys by ensuring they are available before processing requests, thereby streamlining startup and readiness checks.

Highlights

  • New Ready() method: A new Ready() method has been added to the jwks.Remote struct. This method allows callers to block until all configured issuer keys have been fetched at least once, or until the provided context is canceled.
  • Internal readiness signaling: Each trustedIssuer now includes a ready channel. This channel is closed once the initial set of public keys for that issuer has been successfully fetched, signaling its readiness.
  • Simplified test setup: The remote_test.go file has been updated to utilize the new Ready() method, replacing a manual polling loop that previously waited for keys to be available. This makes the test more robust and concise.
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.

@rthellend rthellend marked this pull request as ready for review January 30, 2026 18:25
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 introduces a Ready() method to jwks.Remote to signal when initial JWKS fetches are complete. While this is a useful feature, the current implementation of Ready() has a critical flaw that can lead to a deadlock, and it doesn't correctly handle context cancellation. Additionally, the tests for this new functionality are not comprehensive enough to cover important edge cases. I've provided detailed comments on these issues.

@rthellend
Copy link
Collaborator Author

/gemini 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 introduces a Ready() method to jwks.Remote to allow waiting for the initial fetch of all issuer keys. This is a useful addition that simplifies client code, as demonstrated by the test case simplification.

However, there is a critical race condition in the implementation that can lead to a panic due to a channel being closed twice. When an issuer is removed via SetIssuers at the same time its keys are being fetched by fetchJWKS, both methods might attempt to close the same ready channel.

I've provided suggestions to fix this using sync.Once to ensure the channel is closed safely and only once. This requires a small addition to the trustedIssuer struct.

@rthellend rthellend merged commit 383e293 into main Jan 30, 2026
5 checks passed
@rthellend rthellend deleted the jwks-ready branch January 30, 2026 18:47
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.

1 participant