-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: goroutine leak #5364
fix: goroutine leak #5364
Conversation
Welcome @0xff-dev! |
Hi @0xff-dev. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/ok-to-test |
Thanks for your contribution! Please add any tests that check this bug fixed. |
Hi @koba1t , The code has been updated. During my local testing, I encountered a failure in the last test when utilizing an unbuffered channel. |
@koba1t Based on the execution results of the two change actions, it appears that the |
_ = TimedCall("expect no goroutine leaks", time.Second, func() error { | ||
time.Sleep(2 * time.Second) | ||
return fmt.Errorf("not done") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you be more specify on what has not done? it would help a lot. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the misrepresentation here.
not done
I would say would cause the goroutine to fail to exit and not finish.
Would it be better to change it to return fmt.Error("function done")
? Or just return nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I‘m not buying just return nil, I think something like goroutine to fail to exit and not finish
or function done
is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, the code has been changed to return fmt.Errorf("function done")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small suggestions
api/internal/utils/timedcall_test.go
Outdated
if beforeGroutine != afterGoroutine { | ||
t.Fatal("goroutine leak") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestion:
if beforeGroutine != afterGoroutine { | |
t.Fatal("goroutine leak") | |
} | |
require.NotEqual(t, beforeGoroutine, afterGoroutine, "goroutine leak") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @stormqueen1990 , I think it should be require.Equal
here. Because we modified the unbuffered channel
to be buffered, it should be equal when the test is done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I forgot to invert the test when I typed, sorry about that 😅
api/internal/utils/timedcall_test.go
Outdated
@@ -62,3 +63,15 @@ func TestTimedCallSlowWithError(t *testing.T) { | |||
t.Fail() | |||
} | |||
} | |||
|
|||
func TestTimedCallGoroutineLeak(t *testing.T) { | |||
beforeGroutine := runtime.NumGoroutine() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo in variable name:
beforeGroutine := runtime.NumGoroutine() | |
beforeGoroutine := runtime.NumGoroutine() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one minor comment
api/internal/utils/timedcall_test.go
Outdated
|
||
func TestTimedCallGoroutineLeak(t *testing.T) { | ||
beforeGroutine := runtime.NumGoroutine() | ||
_ = TimedCall("expect no goroutine leaks", time.Second, func() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function has no special complex logic. So ignore the error.
I just looked at the other test examples and none of them ignored the error, so i need to change it, thanks for the review.
@charles-chenzz @stormqueen1990 @koba1t I want to use |
you can push up an quick example to demonstrate it |
@@ -7,6 +7,7 @@ require ( | |||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 | |||
github.com/imdario/mergo v0.3.13 | |||
github.com/stretchr/testify v1.8.1 | |||
go.uber.org/goleak v1.3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a note here for other reviewers: I double checked if this dependency is OK by checking the allowlist here . MIT licenses are allowed, which looks like this repo is covered under, so this should be OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also check k/k, most of the deps on it are MIT and apache2. so I think goleak
from uber which MIT license as well will be OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/assign @natasha41575 @koba1t
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 0xff-dev, natasha41575 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
fix: goroutine leak