Skip to content

workloadapi: return an error from WaitUntilUpdated once the source is closed - #464

Open
vmsilvamolina wants to merge 1 commit into
spiffe:mainfrom
vmsilvamolina:fix/wait-until-updated-closed
Open

vmsilvamolina wants to merge 1 commit into
spiffe:mainfrom
vmsilvamolina:fix/wait-until-updated-closed

Conversation

@vmsilvamolina

Copy link
Copy Markdown

Fixes #460.

The Close comment of X509Source, JWTSource and BundleSource says other source methods return an error after Close. The getters do, but WaitUntilUpdated did not:

  1. Called after Close, it blocked until the context was done and returned the context error.
  2. A goroutine already waiting was not woken by Close; with context.Background() it stayed blocked forever.
  3. If an update was pending when the source was closed, it returned nil, as if the source had been updated.

Change

  • watcherBase gets a closedCh that closeBase closes before cancelling and waiting for the background goroutines, so blocked waiters wake up right away.
  • waitUntilUpdated checks closedCh first (so a pending update is not reported after Close) and also selects on it while waiting. It returns an unexported errSourceClosed.
  • X509Source, JWTSource, BundleSource and WITSource wrap that error with their usual prefix, so callers get the same x509source: source is closed / jwtsource: … / bundlesource: … / witsource: … message as the getters. The doc comments mention the new behavior.

WITSource shares watcherBase, so it gets the same fix. A zero-value WITSource has a nil closedCh; closeBase guards against closing it.

Tests

  • The existing *FailsCallsIfClosed / TestWITSourceClose tests now also call WaitUntilUpdated after Close.
  • TestX509SourceCloseUnblocksWaitUntilUpdated: a waiter using context.Background() is unblocked by Close.
  • TestX509SourceWaitUntilUpdatedIgnoresUpdatePendingAtClose: an update applied but not yet consumed before Close is not reported as an update.

Before the fix, the new assertions fail with context deadline exceeded and the blocked-waiter test hangs. With the fix, go test -race ./workloadapi/ passes (also with -count=3 on the close tests), and make lint reports 0 issues.

…ce is closed

Signed-off-by: Victor Silva <vmsilvamolina@gmail.com>
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.

workloadapi: WaitUntilUpdated does not return an error after a source is closed

2 participants