Repository navigation
fix(workloadapi): reconnect watches when the server completes the stream - #541
Open
amartinezfayo wants to merge 1 commit into
Open
amartinezfayo wants to merge 1 commit into
amartinezfayo wants to merge 1 commit into
Conversation
Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
amartinezfayo
marked this pull request as ready for review
December 4, 2026 12:09
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
Makes the X.509 context, X.509 bundles and JWT bundles watches reconnect when the Workload API server completes the stream without an error.
X509ContextException,X509BundleExceptionorJwtBundleException) with an EOFException as its cause.DefaultWorkloadApiClientclass Javadoc describes the new behavior, and there is a changelog entry under Unreleased.Workload API stream is completed.Why
A stream that ended with an OK status used to stop the watch. onCompleted closed the context and logged at INFO, and the watcher was never told.
DefaultX509Sourceand the JWT sources kept serving their last SVID and bundles and never received another rotation, so the workload looked healthy until that SVID expired.The SPIFFE Workload API specification covers this in section 4.2. The connection may be terminated by either the server or the client at any time, and the client should then establish a new connection. go-spiffe already behaves this way. It treats the end of the stream like any other error that is not a cancellation and retries with backoff.
A SPIRE agent does not trigger this today, because it drops the connection on shutdown and clients see
UNAVAILABLE. Any Workload API server that drains its streams gracefully on shutdown ends them with OK, and every agent restart then stopped the watches of the Java workloads connected to it.One consequence to be aware of is that a successful update resets the backoff, as it does in go-spiffe. A server that sends an update and then completes every stream is reconnected to at the initial delay for as long as it keeps doing that.
How tested
StreamObserversTestfor each watch type. A completed stream schedules a retry without notifying the watcher and without cancelling the watch context. When the retry cannot continue, the watcher receives the typed error with the EOFException cause.DefaultWorkloadApiClientStreamCompletedTestwith an in-process server that completes the first stream of each watch, before or after an update. The client reconnects and receives the next update, with no error reported.main.FakeWorkloadApicompletes each stream after one response, so watches against it now reconnect. Its newwithoutCompletionhelper keeps a stream open, and the fake inDefaultWorkloadApiClientPermissionDeniedRetryTestuses it so that its request counts do not depend on timing../gradlew buildpasses on JDK 17 (703 core, 115 provider and 74 helper tests).