Repository navigation
Memory leak: fix the scheduler's goroutine leakage - #4233
Conversation
|
Skipping CI for Draft Pull Request. |
7ef79af to
0039f51
Compare
Signed-off-by: Maël Valais <[email protected]>
Signed-off-by: Maël Valais <[email protected]>
|
/assign |
irbekrm
left a comment
There was a problem hiding this comment.
Fantastic work on this, I learned more about go timers whilst reviewing :)
So if I understand correctly, the issue was that when the timer was stopped externally we did not actually exit the goroutine whereas now we will do it here.
I've read through the code and verified that the new unit test fails with the old version of the code- so the fix looks right.
I've added some nits, but generally happy to approve.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: irbekrm, maelvls The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Adding a hold in case you want to address the few comments, but also happy for you to unhold /hold |
|
/retest |
Signed-off-by: Maël Valais <[email protected]>
You are correct, |
|
This looks great to me. /lgtm |
|
@jakexks: new pull request created: #4270 DetailsIn response to this:
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/test-infra repository. |
…tion" This reverts commit 641960b. The reason we decided to revert this is that we are unsure about the implications of adding the scheduledWorkQueue.Forget call. The new Forget call is left untested, and it makes us nervous not to know exactly if it works as intended. The "Forget" memory leak that we are reverting now is the cause of a tiny faction of the overall memory leakage that was fixed in the PR cert-manager#4233. The vast majority of the memory leak came from the bug that was in the sheduler itself. Reverting this means that some goroutines will be leaked, but only when a Certificate gets removed and never recreated with the same name. Signed-off-by: Maël Valais <[email protected]>
This reverts commit 641960b. The reason we decided to revert this is that we are unsure about the implications of adding the scheduledWorkQueue.Forget call. The new Forget call is left untested, and it makes us nervous not to know exactly if it works as intended. The "Forget" memory leak that we are reverting now is the cause of a tiny faction of the overall memory leakage that was fixed in the PR cert-manager#4233. The vast majority of the memory leak came from the bug that was in the sheduler itself. Reverting this means that some goroutines will be leaked, but only when a Certificate gets removed and never recreated with the same name. Signed-off-by: Maël Valais <[email protected]>
…rt-manager#9248) The scheduledWorkQueue.afterFunc field was added for testing purposes in cert-manager#4233, but Add never used it, so tests ran against real timers and TestAdd raced on the mock clock state under -race. Rather than wiring the dead hook up, delete it: with Go 1.26 the tests can use testing/synctest, which drives the real afterFunc through k8s.io/utils clock.RealClock deterministically. This removes the unsynchronised mockAfter bookkeeping that cert-manager#9248 flagged, makes the "fired early" check actually fail when Add mis-schedules, and catches goroutine leaks without runtime.NumGoroutine counting. Fixes cert-manager#9248 Signed-off-by: Shashank Varma <[email protected]>
) (#9311) The scheduledWorkQueue.afterFunc field was added for testing purposes in #4233, but Add never used it, so tests ran against real timers and TestAdd raced on the mock clock state under -race. Rather than wiring the dead hook up, delete it: with Go 1.26 the tests can use testing/synctest, which drives the real afterFunc through k8s.io/utils clock.RealClock deterministically. This removes the unsynchronised mockAfter bookkeeping that #9248 flagged, makes the "fired early" check actually fail when Add mis-schedules, and catches goroutine leaks without runtime.NumGoroutine counting. Fixes #9248 Signed-off-by: Shashank Varma <[email protected]> Co-authored-by: Shashank Varma <[email protected]>
A memory leak was identified in #4224. I found out that it was caused by our scheduler that was not stopping its timers. We probably thought that timer.Stop would close the
timer.Cchannel, but it does not as per the documentation:This go playground example shows that
timer.Cis never closed.I wrote a unit test to show the leakage:
% go test ./pkg/scheduler --- FAIL: Test_afterFunc (0.22s) --- FAIL: Test_afterFunc/stop_works (0.12s) scheduler_test.go:56: 3 goroutines before, 10003 goroutines after scheduler_test.go:58: Error Trace: scheduler_test.go:58 Error: Max difference between 3 and 10003 allowed is 100, but difference was -10000 Test: Test_afterFunc/stop_works FAIL/kind bug
Fixes #4224