Repository navigation
fix(workloadapi): stop newSource from storing defaults in the source options - #499
Merged
maxlambrecht merged 1 commit intoNov 5, 2026
Merged
Conversation
maxlambrecht
approved these changes
Nov 5, 2026
maxlambrecht
left a comment
Member
There was a problem hiding this comment.
Reviewed against #497. The fix consistently avoids mutating caller options across all three source factories while preserving existing behavior for explicitly supplied clients.
LGTM
…options DefaultX509Source.newSource, DefaultJwtSource.newSource and CachedJwtSource.newSource stored the Workload API client they created, and DEFAULT_TIMEOUT, in the options object passed by the caller. When initialization failed, for example because initTimeout expired before the SPIRE agent was available, newSource closed the source and so closed that client, but the options kept a reference to it. Every later newSource call with the same options reused the closed client and failed immediately with "Cannot register watch on closed Workload API client", so a retry loop never recovered even after the agent came up. After a successful call, a second source created from the same options shared the first one's client, and closing either source broke the other. Keep the client and the timeout in local variables instead. newSource no longer modifies its argument, and each call without a configured client creates its own. A client set in the options is used, and closed with the source, as before. Fixes spiffe#497 Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
maxlambrecht
force-pushed
the
fix/source-options-client-reuse
branch
from
November 5, 2026 20:59
4d4b825 to
6ab9238
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
DefaultX509Source.newSource,DefaultJwtSource.newSourceandCachedJwtSource.newSourcenow keep the Workload API client they create, and the default init timeout, in local variables. Before, they stored them in the options object passed in.newSourceno longer modifies its argument, and each call without a configuredworkloadApiClientcreates its own client. A client set in the options is used, and closed with the source, as before.Fixes #497
Why
When init failed, for example because
initTimeoutexpired before the SPIRE agent was up,newSourceclosed the source and so closed the client it had created. The options still held that client. Every laternewSource(options)call reused it and failed immediately withIllegalStateException: Cannot register watch on closed Workload API client. A startup loop retryingnewSourcewith the same options never recovered, even after the agent became available.After a successful call, a second source created from the same options shared the first one's client, so closing either source broke the other.
This is the same pattern #494 fixes for
DefaultWorkloadApiClient.newClientandClientOptions, one level up.How tested
newSource_timeout_retryWithSameOptions_createsNewClientinDefaultX509SourceTest,DefaultJwtSourceTestandCachedJwtSourceTestcallsnewSourcetwice with the same options, pointing at a socket nobody listens on. It checks that both calls fail with the init timeout and that the options still have no client. The JWT variants also check thatinitTimeoutis still unset.expected: <Timeout waiting for ...> but was: <Cannot register watch on closed Workload API client>../gradlew :java-spiffe-core:check :java-spiffe-core:japicmp :java-spiffe-core:javadocon JDK 17.