kops icon indicating copy to clipboard operation
kops copied to clipboard

Global download backoff has no jitter, so nodes retry in lockstep

Open 1991santhu opened this issue 4 months ago • 2 comments

What happened

pkg/backoff.computeBackoff produces a deterministic doubling sequence, so every node running nodeup computes the identical set of pause durations — 2s, 4s, 8s … capped at 5m — for the same sequence of failures:

func computeBackoff() time.Duration {
	globalBackoffMutex.Lock()
	defer globalBackoffMutex.Unlock()

	v := globalBackoff
	v = v + v
	if v > maxGlobalBackoff {
		v = maxGlobalBackoff
	}
	globalBackoff = v

	return v
}

DoGlobalBackoff sleeps for exactly that value. Its own comment states the purpose:

// DoGlobalBackoff performs a sleep with a pretty slow backoff.
// The primary use is to rate-limit repeated downloads, to prevent runaway bandwidth bills

The pause does limit each node's individual request rate. What it does not do is decorrelate nodes from each other. Nodes that come up together — a scale-up, an instance-group rollout, a spot-interruption replacement wave — hit the same failing or throttled download at roughly the same moment, sleep for the same duration, and retry at the same instant. Once the value saturates at maxGlobalBackoff, the whole group continues retrying in unison every five minutes for as long as the condition lasts.

So the aggregate request pattern remains bursty, which is the thing the pause is intended to prevent. The larger the group, the larger each burst.

The only caller today is upup/pkg/fi/nodeup/nodetasks/load_image.go, so the practical exposure is image pulls during node startup — which is exactly when many nodes are doing the same thing at the same time.

What you expected to happen

Retry attempts from independent nodes to be spread out rather than aligned, so that a throttled or failing registry sees a smoothed request rate rather than synchronised bursts.

How to reproduce it

I want to be straightforward here: I have not reproduced this at cluster scale. The report is from reading the code, and the mechanism is deterministic enough to be checked directly:

// pkg/backoff/backoff_test.go — existing test, already asserts this
expected := []time.Duration{
	2 * time.Second, 4 * time.Second, 8 * time.Second, ...
}

TestBackoff already documents that the sequence is fixed. Any two processes running the same code produce the same delays, so no run-time observation is needed to establish alignment — it follows from the function being pure.

To observe it in a cluster: scale an instance group by a meaningful number of nodes with a registry that rate-limits (or is briefly unavailable), and look at the arrival timestamps of image-pull attempts at the registry. Retries appear in tight clusters rather than spread across the interval.

Anything else we need to know?

The usual fix is jitter. I have opened #18663, which applies equal jitter in DoGlobalBackoff — randomising the upper half of the interval while retaining the lower half as a floor — and leaves computeBackoff deterministic so that TestBackoff and the escalation state remain exactly as they are. Happy to change the approach if maintainers prefer full jitter, a configurable bound, or a different placement.

Separately, and unrelated to the fix: go test -count=2 ./pkg/backoff/... fails on the second iteration, because globalBackoff is package-level state that persists between runs in the same process, so TestBackoff is not idempotent. I confirmed this reproduces on master without any of my changes. I left it alone to keep the PR to one concern, but can send a separate PR resetting the global at the start of the test if that is wanted.

Kubernetes version / Cloud provider / Other

Not version-specific; the code path is unchanged on master as of this report.

1991santhu avatar Aug 04 '26 17:08 1991santhu

Closing: this is from reading the code, with no reproduction and no report of it happening in practice. Happy to look again if someone hits it.

/close

hakman avatar Aug 04 '26 19:08 hakman

@hakman: Closing this issue.

In response to this:

Closing: this is from reading the code, with no reproduction and no report of it happening in practice. Happy to look again if someone hits it.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

kubernetes-prow[bot] avatar Aug 04 '26 19:08 kubernetes-prow[bot]