api: set Stop field on ExponentialBackOff in LifetimeWatcher#31896
Open
raman1236 wants to merge 2 commits into
Open
api: set Stop field on ExponentialBackOff in LifetimeWatcher#31896raman1236 wants to merge 2 commits into
raman1236 wants to merge 2 commits into
Conversation
|
@ramanvasi is attempting to deploy a commit to the HashiCorp Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Friendly ping — this PR fixes a subtle regression where |
When the backoff package was upgraded from v3 to v4 in PR hashicorp#26868, the ExponentialBackOff struct in lifetime_watcher.go was directly initialized instead of using the backoff.NewExponentialBackOff() constructor. In v4, the Stop field defaults to the zero value (0) instead of backoff.Stop (-1s). This meant that when MaxElapsedTime was exceeded during persistent renewal failures, NextBackOff() returned 0 instead of backoff.Stop, so the check "sleepDuration == backoff.Stop" never matched and doneCh never received an error. Fix: Add "Stop: backoff.Stop" to the struct literal so that the LifetimeWatcher properly detects when the backoff has been exhausted and propagates the renewal error through doneCh. Fixes hashicorp#28611
e3cd10f to
b51efd5
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.
Description
Fixes a regression introduced in #26868 where the backoff package upgrade from v3 to v4 broke error propagation in the
LifetimeWatcher.Root Cause
When the
ExponentialBackOffstruct was upgraded from backoff v3 to v4, it was directly initialized instead of usingbackoff.NewExponentialBackOff(). In v4, theStopfield onExponentialBackOffhas a zero value of0(atime.Duration), but the sentinel valuebackoff.Stopis-1s. The constructorNewExponentialBackOff()setsStop: backoff.Stop, but the direct struct initialization inlifetime_watcher.goomitted this field.This means that when
MaxElapsedTimeis exceeded during persistent renewal failures,NextBackOff()returns0(the struct'sStopfield value) instead ofbackoff.Stop(-1s). The subsequent check:never matches, so
doneChnever receives the renewal error. The watcher eventually exits via the grace period check returningnil, silently losing the error.Fix
Add
Stop: backoff.Stopto theExponentialBackOffstruct literal so thatNextBackOff()correctly returnsbackoff.Stopwhen the maximum elapsed time is exceeded. This is a one-line change.Testing
TestLifetimeWatcherErrorBackoffStopsregression test that creates aLifetimeWatcherwith a short lease and persistent renewal failures, verifying the watcher terminates promptly instead of getting stuckTestLifetimeWatcher,TestRenewer_NewRenewer, andTestCalcSleepPeriodtests continue to passFixes #28611