fix: stop GameServer sub-controller from exhausting rate limiters #4775
@nrwiersma - be good to see if you can test this in prod, see if it solves the issue.
Build Succeeded :partying_face:
_Build Id: 02290423-75da-4e7e-b4c3-80ed10161235_
The following development artifacts have been built, and will exist for the next 30 days:
image: us-docker.pkg.dev/agones-images/ci/agones-controller:1.62.0-dev-6d18a45
image: us-docker.pkg.dev/agones-images/ci/agones-extensions:1.62.0-dev-6d18a45
image: us-docker.pkg.dev/agones-images/ci/agones-sdk:1.62.0-dev-6d18a45-linux
image: us-docker.pkg.dev/agones-images/ci/agones-ping:1.62.0-dev-6d18a45
image: us-docker.pkg.dev/agones-images/ci/agones-allocator:1.62.0-dev-6d18a45
image: us-docker.pkg.dev/agones-images/ci/agones-processor:1.62.0-dev-6d18a45
Linux C++ SDK (build): agonessdk-1.62.0-dev-6d18a45-linux-arch_64.tar.gz
SDK Server: agonessdk-server-1.62.0-dev-6d18a45.zip
A preview of the website (the last 30 builds are retained):
To install this version:
git fetch https://github.com/googleforgames/agones.git pull/4775/head:pr_4775 && git checkout pr_4775
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.62.0-dev-6d18a45
Just to point out that you are potentially double rate limiting here, as the kube ClientSet also has a rate limiter built in, but I think it likely is more generous then this.
I will build this today and we can test it in prod for this evenings load. Will report back.
Honestly, that's by design - basically so that a big dump of events into here doesn't overload the other systems that really should have higher priority.
<!-- ccr-overview-v2 -->
🟢 Approval recommended
The focused implementation preserves retry behavior, prevents resync token consumption, and includes appropriate controller-level tests.
0 open findings
<details>
<summary><strong>What changed in this PR</strong></summary>
Prevents informer resyncs from exhausting GameServer sub-controller workqueue rate limiters.
Changes:
| File | Description |
| ---- | ----------- |
| pkg/gameservers/gameservers.go | Defines the shared state-update limiter. |
| pkg/gameservers/succeeded.go | Updates Shutdown enqueue and throttling behavior. |
| pkg/gameservers/succeeded_test.go | Tests Shutdown limiter placement. |
| pkg/gameservers/missing.go | Updates Unhealthy enqueue and throttling behavior. |
| pkg/gameservers/missing_test.go | Tests missing-Pod limiter placement. |
| pkg/gameservers/health.go | Updates health-event enqueue and throttling behavior. |
| pkg/gameservers/health_test.go | Tests health limiter placement and bypass paths. |
</details>
🧠 Review effort: Balanced
---
💡 <a href="/agones-dev/agones/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
We can confirm this fixes the issue in production.
We can confirm this fixes the issue in production.
@nrwiersma if only you were an approver on Agones, we could merge this.... right now 😄
_insert guilt trip_ 😆
Looking great ! 🚀
Build Succeeded :partying_face:
_Build Id: 0571771d-5b5e-44c3-95e1-79ddd76ef40d_
The following development artifacts have been built, and will exist for the next 30 days:
image: us-docker.pkg.dev/agones-images/ci/agones-controller:1.62.0-dev-5db4e7b
image: us-docker.pkg.dev/agones-images/ci/agones-extensions:1.62.0-dev-5db4e7b
image: us-docker.pkg.dev/agones-images/ci/agones-sdk:1.62.0-dev-5db4e7b-linux
image: us-docker.pkg.dev/agones-images/ci/agones-ping:1.62.0-dev-5db4e7b
image: us-docker.pkg.dev/agones-images/ci/agones-allocator:1.62.0-dev-5db4e7b
image: us-docker.pkg.dev/agones-images/ci/agones-processor:1.62.0-dev-5db4e7b
Linux C++ SDK (build): agonessdk-1.62.0-dev-5db4e7b-linux-arch_64.tar.gz
SDK Server: agonessdk-server-1.62.0-dev-5db4e7b.zip
A preview of the website (the last 30 builds are retained):
To install this version:
git fetch https://github.com/googleforgames/agones.git pull/4775/head:pr_4775 && git checkout pr_4775
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.62.0-dev-5db4e7b
nrwiersma
markmandel
What type of PR is this?
/kind bug
What this PR does / Why we need it:
The
SucceededController,MissingPodControllerandHealthControllercallWorkerQueue.Enqueue(
AddRateLimited) from their informer handlers. Those handlers fire on every 30s informer resync.Each rate-limited enqueue spends a token from the queue's shared bucket (10/s, burst 100), even when
the key is already queued. Every key still waiting costs one or two tokens per resync, and the bucket
only refills 300 tokens per 30s. So after a large wave of completed, missing or failed Pods, plus
ongoing churn, the bucket's backlog can grow without bound.
When that happens:
Allocatedlong after their Pod hasSucceeded, or aren't markedUnhealthy,until the controller is restarted.
conflict sends the key straight to the 1000s backoff cap.
This PR:
EnqueueImmediatelyin the informer handlers of all three controllers.- The queue deduplicates keys, so resyncs no longer cost anything.
- The resync-driven recovery paths from #4480 are kept.
Shutdown/UnhealthyUpdateitself with arate.Limiterinstead.- It uses 10/s and a burst of 100, the same limits as the default workqueue bucket.
- It runs after the cache checks, so syncs that change nothing never wait.
- Each controller keeps its own limiter, so total write capacity is unchanged.
newStateUpdateLimiterinpkg/gameservers/gameservers.go.#4774 has the full analysis: simulation results before and after the change, and the alternatives
we considered.
Which issue(s) this PR fixes:
Closes #4774
Did you use AI tools in preparing this PR?:
Y.
Special notes for your reviewer:
old.ResourceVersion == new.ResourceVersion? On the GameServerhandlers, that would remove the #4480 recovery paths, which exist to catch missed Pod events on
resync. Filtering only the Pod handlers halves the cost, but in the simulation it still grows
without bound.
Separate limiters keep total write throughput the same. One shared limiter would cut it by two
thirds.
Waitalwayserrors). The tests check that a real state change is gated by the limiter (error, no update), and
that no-op syncs never wait on it.
make -C build lint test-gopasses.