Skip to content

[release-1.21] Fix flaky goroutine-leak test in pkg/scheduler - #9261

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:release-1.21from
cert-manager-bot:cherry-pick-9217-to-release-1.21
Sep 3, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:release-1.21from
cert-manager-bot:cherry-pick-9217-to-release-1.21

Conversation

@cert-manager-bot

@cert-manager-bot cert-manager-bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

This is an automated cherry-pick of #9217

Fixes #9250

/assign wallrj

NONE

wallrj-cyberark and others added 2 commits September 3, 2026 08:34
Test_afterFunc/stop_works starts 10000 afterFunc goroutines, cancels them
all, then sleeps a fixed 100ms before comparing runtime.NumGoroutine()
against the baseline taken at the start. Those goroutines exit
asynchronously, so on a loaded machine 100ms is not nearly long enough for
10000 of them to be scheduled and exit, and the test fails despite there
being no leak.

Reproducing it showed a second, independent problem. The assertion used
assert.InDelta, which fails in both directions, but this is a leak check
where only an increase matters. Tests sharing the binary run concurrently,
so the baseline can include goroutines that have since exited, leaving
fewer at the end than there were at the start.

- Poll for the count to come back down, up to a 30s deadline, rather than
  sleeping a fixed amount. A real leak never recovers, so it still fails
  once the deadline passes.
- Assert an upper bound with assert.LessOrEqual instead of a two-sided
  delta.

Verified by pinning the prebuilt test binary to a single saturated core:
2 of 8 runs failed before the change, exercising both directions (once
1494 goroutines above the baseline, once 1494 below it), and 15 of 15
passed after.

Also checked the test still catches a real leak rather than merely having
been made unfailable, by temporarily replacing the "case <-cancelCh:
return" in afterFunc with a block that never returns. It fails as
intended, with "10000 is not less than or equal to 100".

Signed-off-by: Richard Wall <[email protected]>
Review of the previous commit found two problems:

- The comment justifying the one-sided assertion claimed that tests
  sharing the binary run concurrently, but no test in this package calls
  t.Parallel() and Test_afterFunc runs first, so nothing runs
  concurrently with it. The below-baseline counts come from
  `go test -count=N` reruns, where one run's baseline includes
  still-draining goroutines from the previous run.

- The hand-rolled deadline/sleep loop re-implemented assert.Eventually,
  which is already imported here and is the established pattern for
  poll-until-deadline assertions elsewhere in this repository.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
@cert-manager-prow cert-manager-prow Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Sep 3, 2026
@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 3, 2026
@wallrj

wallrj commented Sep 3, 2026

Copy link
Copy Markdown
Member

/kind flake

@cert-manager-prow cert-manager-prow Bot added kind/flake Categorizes issue or PR as related to a flaky test. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 3, 2026
@wallrj

wallrj commented Sep 3, 2026

Copy link
Copy Markdown
Member

/lgtm
/approve

@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj

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

@cert-manager-prow cert-manager-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. labels Sep 3, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit b6af109 into cert-manager:release-1.21 Sep 3, 2026
6 checks passed
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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/flake Categorizes issue or PR as related to a flaky test. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants