← Back to Pull requests

fix: stop GameServer sub-controller from exhausting rate limiters #4775

Merged
markmandel merged 7 files (246 lines) on Oct 14, 2026 17:12 UTC
View on GitHub
markmandel markmandel commented on Oct 11, 2026 22:09 UTC
Author

What type of PR is this?

/kind bug

What this PR does / Why we need it:

The SucceededController, MissingPodController and HealthController call WorkerQueue.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:

  • GameServers stay Allocated long after their Pod has Succeeded, or aren't marked Unhealthy,

  • until the controller is restarted.
  • Each enqueue also raises the key's per-item failure count. So after a long wait, a single update

  • conflict sends the key straight to the 1000s backoff cap.

    This PR:

  • Uses EnqueueImmediately in 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.
  • Throttles the Shutdown / Unhealthy Update itself with a rate.Limiter instead.

  • - 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.
  • Puts the shared limits and the reasoning in one place: newStateUpdateLimiter in

  • pkg/gameservers/gameservers.go.
  • Leaves failed syncs retrying with backoff through the workerqueue, as before.
  • #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:

  • Why not filter resyncs with old.ResourceVersion == new.ResourceVersion? On the GameServer

  • handlers, 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.
  • Why one limiter per controller rather than a shared one? Today each queue has its own bucket.

  • Separate limiters keep total write throughput the same. One shared limiter would cut it by two
    thirds.
  • Tests: each controller has a new unit test that swaps in a zero-burst limiter (Wait always

  • errors). 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-go passes.

    Diff: 246 lines (+240 / -6) across 7 files Reviewer: nrwiersma Review duration: 4022m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.45) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 246 lines diff across 7 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 5 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    92%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.330
    Real PR Conversation Timeline
    12 items
    markmandel markmandel commented on Oct 11, 2026 22:32 UTC
    Author

    @nrwiersma - be good to see if you can test this in prod, see if it solves the issue.

    agones-bot agones-bot commented on Oct 11, 2026 23:11 UTC
    Bot

    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):

  • https://6d18a45-dot-preview-dot-agones-images.appspot.com/
  • 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
    

    nrwiersma nrwiersma commented on code on Oct 12, 2026 03:28 UTC
    Code Review
    pkg/gameservers/health.go:1
    @@ -274,6 +278,10 @@ func (hc *HealthController) syncGameServer(ctx context.Context, key string) erro
     		}
     	}
     
    +	if err := hc.unhealthyLimiter.Wait(ctx); err != nil {

    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.

    nrwiersma nrwiersma commented on Oct 12, 2026 03:30 UTC
    Reviewer

    I will build this today and we can test it in prod for this evenings load. Will report back.

    markmandel markmandel commented on code on Oct 12, 2026 05:39 UTC
    Code Review
    pkg/gameservers/health.go:1
    @@ -274,6 +278,10 @@ func (hc *HealthController) syncGameServer(ctx context.Context, key string) erro
     		}
     	}
     
    +	if err := hc.unhealthyLimiter.Wait(ctx); err != nil {

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 12, 2026 18:20 UTC
    Reviewer

    <!-- 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:

  • Uses immediate, deduplicated informer enqueues.

  • Throttles only state-changing API updates at 10/s with burst 100.

  • Adds tests confirming limiter gating and no-op behavior.
  • | 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>

    nrwiersma nrwiersma approved these changes on Oct 13, 2026 08:05 UTC
    Approved Reviewer

    We can confirm this fixes the issue in production.

    markmandel markmandel commented on Oct 13, 2026 17:45 UTC
    Author

    We can confirm this fixes the issue in production.

    !Amazing!

    markmandel markmandel commented on Oct 13, 2026 20:13 UTC
    Author

    @nrwiersma if only you were an approver on Agones, we could merge this.... right now 😄

    _insert guilt trip_ 😆

    lacroixthomas lacroixthomas approved these changes on Oct 14, 2026 15:57 UTC
    Approved Reviewer

    Looking great ! 🚀

    agones-bot agones-bot commented on Oct 14, 2026 17:09 UTC
    Bot

    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):

  • https://5db4e7b-dot-preview-dot-agones-images.appspot.com/
  • 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
    

    Reviewers
    Assignees
    markmandel markmandel
    Labels
    risk: low confidence: 92.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 92.4% · Lower = rushed or shallow review
    92.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.4% · Safe to merge
    3.4%