You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Primary lease take-over polling can stall past RetryPeriod #11349
tryTakeOver reads the primary lease via r.lock.Get(ctx), using the caller's context as-is with no per-call deadline. preAcquire calls tryTakeOver in a loop and expects each attempt to return within roughly RetryPeriod (2s by default), whether it succeeds, finds the lease unavailable, or errors out.
Because the Get call carried no timeout of its own, if the Kubernetes API server was unreachable or unresponsive, the call could block for however long the underlying client-go transport takes to give up on its own — not necessarily bounded by RetryPeriod. During that time the take-over loop made no progress: it couldn't observe the lease, couldn't detect a stale holder, and couldn't retry on schedule.
The practical effect is that a replica trying to take over a stale primary's lease (e.g. during a failover) could see its take-over attempts stall for an unpredictable, potentially long time whenever the API server was slow or unreachable, instead of retrying at the intended cadence.
@leonardoce, your analysis is spot on. In tryTakeOver, the r.lock.Get(ctx) call passes the caller's context with no per-call deadline [1]. The preAcquire loop only resets its timer to RetryPeriodaftertryTakeOver returns [2], so a slow or unreachable API server can stall the entire polling cadence for however long the underlying transport takes to time out.
The fix is straightforward: wrap r.lock.Get (and the r.lock.Update in claim) with a context.WithTimeout(ctx, r.config.RetryPeriod) so each API call is independently bounded:
This mirrors the pattern already used in runLeaderElection after le.Run exits, where a context.WithTimeout(ctx, r.config.RetryPeriod) is applied to the post-exit lease check [3].
For context, the primary lease feature was introduced in #10627 and the defaultRetryPeriod was lowered from 5s to 2s in #10950, so this code is relatively new and the gap is understandable.
Activity
dosubot commentedon Aug 20, 2026
@leonardoce, your analysis is spot on. In
tryTakeOver, ther.lock.Get(ctx)call passes the caller's context with no per-call deadline [1]. ThepreAcquireloop only resets its timer toRetryPeriodaftertryTakeOverreturns [2], so a slow or unreachable API server can stall the entire polling cadence for however long the underlying transport takes to time out.The fix is straightforward: wrap
r.lock.Get(and ther.lock.Updateinclaim) with acontext.WithTimeout(ctx, r.config.RetryPeriod)so each API call is independently bounded:This mirrors the pattern already used in
runLeaderElectionafterle.Runexits, where acontext.WithTimeout(ctx, r.config.RetryPeriod)is applied to the post-exit lease check [3].For context, the primary lease feature was introduced in #10627 and the
defaultRetryPeriodwas lowered from 5s to 2s in #10950, so this code is relatively new and the gap is understandable.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
fix(instance-manager): bound the primary lease take-over Get call (#1…
fix(instance-manager): bound the primary lease take-over Get call (cl…