Skip to content

NO-JIRA: harden watch loop to prevent thread exhaustion#30956

Open
neisw wants to merge 2 commits intoopenshift:mainfrom
neisw:resource-watch-fixes
Open

NO-JIRA: harden watch loop to prevent thread exhaustion#30956
neisw wants to merge 2 commits intoopenshift:mainfrom
neisw:resource-watch-fixes

Conversation

@neisw
Copy link
Copy Markdown
Contributor

@neisw neisw commented Apr 3, 2026

Continuation of #30944

Handle watch error/bookmark events safely, always stop watch streams, and add context-aware retry backoff so reconnects do not spin and accumulate threads.

Made-with: Cursor

@openshift-ci-robot
Copy link
Copy Markdown

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 3, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@neisw: This pull request explicitly references no jira issue.

Details

In response to this:

Continuation of #30944

Handle watch error/bookmark events safely, always stop watch streams, and add context-aware retry backoff so reconnects do not spin and accumulate threads.

Made-with: Cursor

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 30f581a8-719b-4149-9924-7b0ab08d3267

📥 Commits

Reviewing files that changed from the base of the PR and between 3836525 and ba94dc5.

📒 Files selected for processing (2)
  • pkg/resourcewatch/observe/observe.go
  • pkg/resourcewatch/observe/observe_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/resourcewatch/observe/observe_test.go

Walkthrough

Implements retry with exponential backoff and ±25% jitter for resource watches, refines listAndWatchResource event handling (errors, bookmarks, NotFound) and watch shutdown, and adds unit tests covering error events, added events, closed streams, retry delays, and canceled retries.

Changes

Cohort / File(s) Summary
Resource Watch Implementation
pkg/resourcewatch/observe/observe.go
Adds retry loop in ObserveResource with exponential backoff (base 500ms, cap 30s) and ±25% jitter; treats context cancellation/deadline and errUnexpectedObject as terminal; listAndWatchResource now returns immediately on NotFound, defers resourceWatch.Stop(), ignores watch.Bookmark, extracts *metav1.Status from watch.Error events (returns wrapped error), returns errWatchClosed when result channel closes, and tightens unexpected-object handling.
Resource Watch Tests
pkg/resourcewatch/observe/observe_test.go
Adds tests and fakes (fakeNamespaceableResource, trackingWatch). Tests: (1) listAndWatchResource handles watch.Error status (Expired) and stops watch; (2) Added event emits ResourceObservation with matching UID and stops on context cancel; (3) closed watch channel returns errWatchClosed; (4) retry delay/backoff behavior and NotFound delay behavior; also tests waitForRetry with canceled context.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot requested review from deads2k and sjenning April 3, 2026 14:27
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 3, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neisw

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

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 3, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/resourcewatch/observe/observe.go`:
- Around line 73-74: The code in ObserveResource is resetting retryAttempt to 0
when the watch returns nil/ends, which causes immediate reconnects if the watch
stream was closed (ResultChan() closed) rather than a clean end; modify the
logic in the watch loop (observe.go, functions handling the watch and the block
that currently sets retryAttempt = 0) to only reset retryAttempt when the watch
truly ended cleanly (e.g., explicit stop signal or terminal condition), and
treat a closed ResultChan() (receive with ok == false) as a retryable error path
that does NOT reset retryAttempt but increments backoff and returns an error so
backoff applies; apply the same change to the analogous code paths around the
other reset occurrences (the block referenced by lines ~150-153) and add a small
regression test that simulates an already-closed ResultChan() to assert backoff
is not reset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66e3ac20-b4e0-4ad4-935e-ed3260c92694

📥 Commits

Reviewing files that changed from the base of the PR and between 85dec4b and 3836525.

📒 Files selected for processing (2)
  • pkg/resourcewatch/observe/observe.go
  • pkg/resourcewatch/observe/observe_test.go

@openshift-ci-robot
Copy link
Copy Markdown

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@neisw
Copy link
Copy Markdown
Contributor Author

neisw commented Apr 5, 2026

/payload-job periodic-ci-openshift-release-main-nightly-4.22-e2e-gcp-ovn-rt

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 5, 2026

@neisw: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-release-main-nightly-4.22-e2e-gcp-ovn-rt

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/3a7af320-30eb-11f1-8069-b05fa5978c62-0

@openshift-ci-robot
Copy link
Copy Markdown

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 6, 2026

@neisw: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-ovn-fips ba94dc5 link true /test e2e-aws-ovn-fips
ci/prow/e2e-gcp-csi ba94dc5 link true /test e2e-gcp-csi
ci/prow/e2e-gcp-ovn-upgrade ba94dc5 link true /test e2e-gcp-ovn-upgrade
ci/prow/e2e-vsphere-ovn-upi ba94dc5 link true /test e2e-vsphere-ovn-upi
ci/prow/e2e-aws-ovn-microshift-serial ba94dc5 link true /test e2e-aws-ovn-microshift-serial
ci/prow/e2e-aws-ovn-microshift ba94dc5 link true /test e2e-aws-ovn-microshift

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@openshift-trt
Copy link
Copy Markdown

openshift-trt bot commented Apr 7, 2026

Job Failure Risk Analysis for sha: ba94dc5

Job Name Failure Risk
pull-ci-openshift-origin-main-e2e-gcp-ovn Low
[Jira:Node][sig-node] Node non-cnv swap configuration should reject user override of swap settings via KubeletConfig API [OCP-86395] [Suite:openshift/conformance/parallel]
This test has passed 0.00% of 2 runs on release 5.0 [Architecture:amd64 FeatureSet:default Installer:ipi JobTier:standard Network:ovn NetworkStack:ipv4 OS:rhcos9 Owner:eng Platform:gcp Procedure:none SecurityMode:default Topology:ha Upgrade:major] in the last week.
pull-ci-openshift-origin-main-e2e-metal-ipi-ovn-ipv6 Low
[Jira:Node][sig-node] Node non-cnv swap configuration should reject user override of swap settings via KubeletConfig API [OCP-86395] [Suite:openshift/conformance/parallel]
This test has passed 46.34% of 287 runs on release 5.0 [Overall] in the last week.
pull-ci-openshift-origin-main-e2e-vsphere-ovn Low
[Jira:Node][sig-node] Node non-cnv swap configuration should reject user override of swap settings via KubeletConfig API [OCP-86395] [Suite:openshift/conformance/parallel]
This test has passed 46.15% of 13 runs on release 5.0 [Architecture:amd64 FeatureSet:default Installer:ipi JobTier:standard Network:ovn NetworkStack:ipv4 OS:rhcos9 Owner:eng Platform:vsphere Procedure:none SecurityMode:default Topology:ha Upgrade:none] in the last week.
pull-ci-openshift-origin-main-e2e-vsphere-ovn-upi Medium
[sig-auth][Feature:SCC][Early] should not have pod creation failures during install [Suite:openshift/conformance/parallel]
This test has passed 94.89% of 685 runs on release 5.0 [Overall] in the last week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants