Skip to content

backoff: fix a timer leak in RunF - #9486

Open
kenny-ish wants to merge 1 commit into
grpc:masterfrom
kenny-ish:backoff-runf-timer-leak
Open

kenny-ish wants to merge 1 commit into
grpc:masterfrom
kenny-ish:backoff-runf-timer-leak

Conversation

@kenny-ish

Copy link
Copy Markdown

Fixes #9485

What was the problem: If the context is canceled while RunF is executing f, and f returns nil, RunF returns without stopping the timer, even though the timer has been reset (the timer remains active).
What was changed: As described in the diff in the issue. Added defer timer.Stop() and checked the context immediately after f before returning.
Tests: Since this package had no tests, I added a new file, backoff_test.go. In line with the issue's recommendation to cover the entire package with tests, coverage is 100%.
Exponential.Backoff: Upper limit, jitter range, and ensuring values do not go negative.
RunF: Stops on error, resets, cancellation before execution, cancellation while waiting, and cancellation while f is executing (the leak in this case).
Verified: go test -race -cpu 1,4 and ./scripts/vet.sh pass. If I remove the fix, the leak test fails.
I haven't touched the copy of this package in the xDS client, since the issue raises it separately.

RELEASE NOTES: n/a

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: kenny-ish / name: kenny-ish (ba74d34)

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.65%. Comparing base (6c0c296) to head (ba74d34).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9486      +/-   ##
==========================================
+ Coverage   87.61%   87.65%   +0.03%     
==========================================
  Files         436      436              
  Lines       30818    30820       +2     
==========================================
+ Hits        27001    27014      +13     
+ Misses       3816     3805      -11     
  Partials        1        1              
Files with missing lines Coverage Δ
internal/backoff/backoff.go 100.00% <100.00%> (+7.14%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backoff: fix a timer leak in RunF

1 participant