← Back to Pull requests

client-go/reflector: give up on watch-list after incomplete streams #140902

Open
BitWeaverDev opened this pull request with 76 lines diff across 2 files
View on GitHub
BitWeaverDev BitWeaverDev commented on Jul 24, 2026 07:00 UTC
Author

What type of PR is this?

/kind bug

What this PR does / why we need it:

If an aggregated API server accepts a WatchList request, sends some initial
events, and then closes the stream without ever sending the
initial-events-end bookmark, Reflector.watchList() retries the
watch-list request forever inside its own loop. There is no deadline or
retry limit on this path, so a single misbehaving APIService can prevent
the informer from ever completing its initial sync.

In the reported incident this happened to one of the per-resource
QuotaMonitor informers in kube-controller-manager. Because
QuotaMonitor.IsSynced() requires all of its informers to report
HasSynced(), the ResourceQuota controller's workers never started,
ResourceQuota.status.used went stale, and new pods were rejected.

This PR bounds how many times watchList() will re-establish watch-list
requests that end without the bookmark. After three such streams, it
returns an error, which the existing code in ListAndWatchWithContext
already treats as "watch-list didn't work, fall back to a regular list" -
so no changes were needed to the fallback path itself.

Which issue(s) this PR fixes:

Fixes #140890

Special notes for your reviewer:

This PR was written in part with the assistance of generative AI.

The bound counts incomplete streams rather than elapsed time. Those retries
happen with no backoff, so a time bound would hammer the server until it
expired, and a time bound equal to the watch timeout would also leave no
retry for a slow stream that legitimately hit the server-side timeout.
Errors that already back off (connection refused, 429) are not counted.

Does this PR introduce a user-facing change?

``release-note
NONE
``

Diff: 76 lines (+76 / -0) across 2 files Reviewer: tamilmani1989 Review duration: 191720m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.37) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 76 lines diff across 2 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
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.260
Real PR Conversation Timeline
19 items
kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 24, 2026 07:01 UTC
Bot

Please note that we're already in Code Freeze for the upcoming v1.37.0 release.

Adding the milestone to this PR is strictly prohibited without proper approval. If this PR needs to be included in the v1.37.0 release:
1. Technical review: get the PR reviewed and approved as usual (/lgtm and /approve)
2. Inclusion in release: ping @sig-release-leads on the #sig-release Slack channel and suggest to add the v1.37.0 milestone to the PR

linux-foundation-easycla[bot] linux-foundation-easycla[bot] commented on Jul 24, 2026 07:01 UTC
Bot

<a href="https://easycla.lfx.linuxfoundation.org/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-signed.svg?v=2" alt="CLA Signed" align="left" height="28" width="328" ></a><br >The committers listed above are authorized under a signed CLA.<ul><li>:white_check_mark: login: BitWeaverDev / name: BitWeaverDev (04e65c1ec28b01047da4524531f50ab492708400)</li></ul>

kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 24, 2026 07:01 UTC
Bot

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

<details>

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.
</details>

kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 24, 2026 07:01 UTC
Bot

Welcome @BitWeaverDev! <br><br>It looks like this is your first PR to <a href='https://github.com/kubernetes/kubernetes'>kubernetes/kubernetes</a> 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval. <br><br>You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation. <br><br>You can also check if kubernetes/kubernetes has its own contribution guidelines. <br><br>You may want to refer to our testing guide if you run into trouble with your tests not passing. <br><br>If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs! <br><br>Thank you, and welcome to Kubernetes. :smiley:

kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 24, 2026 07:01 UTC
Bot

Hi @BitWeaverDev. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

<details>

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.
</details>

kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 24, 2026 07:01 UTC
Bot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes/kubernetes/pull/140902#" title="Author self-approved">BitWeaverDev</a>
Once this PR has been reviewed and has the lgtm label, please assign liggitt for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

<details open>
Needs approval from an approver in each of these files:

  • staging/src/k8s.io/client-go/tools/cache/OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["liggitt"]} -->

    dims dims commented on Jul 25, 2026 13:54 UTC
    Contributor

    please sign CNCF CLA and reopen

    /close

    BitWeaverDev BitWeaverDev commented on Jul 25, 2026 14:42 UTC
    Author

    /reopen

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 25, 2026 14:42 UTC
    Bot

    @BitWeaverDev: Reopened this PR.

    <details>

    In response to this:

    >/reopen

    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.
    </details>

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 25, 2026 14:42 UTC
    Bot

    Please note that we're already in Code Freeze for the upcoming v1.37.0 release.

    Adding the milestone to this PR is strictly prohibited without proper approval. If this PR needs to be included in the v1.37.0 release:
    1. Technical review: get the PR reviewed and approved as usual (/lgtm and /approve)
    2. Inclusion in release: ping @sig-release-leads on the #sig-release Slack channel and suggest to add the v1.37.0 milestone to the PR

    tamilmani1989 tamilmani1989 commented on Sep 18, 2026 20:48 UTC
    Contributor

    @BitWeaverDev are you still following up on this PR?

    BitWeaverDev BitWeaverDev commented on Sep 20, 2026 10:31 UTC
    Author

    @BitWeaverDev are you still following up on this PR?

    Yes waiting for someone to review.

    tamilmani1989 tamilmani1989 commented on Sep 22, 2026 19:25 UTC
    Contributor

    /test

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Sep 22, 2026 19:26 UTC
    Bot

    @tamilmani1989: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

    <details>

    In response to this:

    >/test

    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.
    </details>

    tamilmani1989 tamilmani1989 commented on code on Sep 22, 2026 19:26 UTC
    Code Review
    staging/src/k8s.io/client-go/tools/cache/reflector.go:1
    @@ -65,6 +65,10 @@ var (
     	defaultBackoffReset  = 2 * time.Minute
     	defaultBackoffFactor = 2.0
     	defaultBackoffJitter = 1.0
    +	// defaultWatchListRetryDuration bounds how long watchList retries
    +	// requests that never deliver the "initial-events-end" bookmark before
    +	// giving up and falling back to a regular list.
    +	defaultWatchListRetryDuration = defaultMinWatchTimeout

    wont 5 mins too long to break retries?

    tamilmani1989 tamilmani1989 commented on Sep 22, 2026 19:27 UTC
    Contributor

    /ok-to-test

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Sep 22, 2026 19:27 UTC
    Bot

    @tamilmani1989: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

    <details>

    In response to this:

    >/ok-to-test

    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.
    </details>

    BitWeaverDev BitWeaverDev commented on code on Nov 02, 2026 20:03 UTC
    Code Review
    staging/src/k8s.io/client-go/tools/cache/reflector.go:1
    @@ -65,6 +65,10 @@ var (
     	defaultBackoffReset  = 2 * time.Minute
     	defaultBackoffFactor = 2.0
     	defaultBackoffJitter = 1.0
    +	// defaultWatchListRetryDuration bounds how long watchList retries
    +	// requests that never deliver the "initial-events-end" bookmark before
    +	// giving up and falling back to a regular list.
    +	defaultWatchListRetryDuration = defaultMinWatchTimeout

    Yes, and it was worse than just slow. When a stream ends without the bookmark, handleListWatch returns no error, so the loop retries immediately with no backoff. A 5 minute bound meant 5 minutes of back-to-back requests against the broken server. It also matched minWatchTimeout, so a slow stream that hit the server-side timeout would get no retry at all.

    I changed it to count incomplete streams instead and give up after 3. Errors that already back off (connection refused, 429) are not counted. The test now checks for exactly 3 attempts before the fallback list.

    Reviewers
    Assignees
    BitWeaverDev BitWeaverDev
    Labels
    risk: low confidence: 89.7% 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: 37.4% (MEDIUM) · Higher = larger blast radius
    37.4%
    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: 89.7% · Lower = rushed or shallow review
    89.7%
    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.9% · Safe to merge
    3.9%