-
Notifications
You must be signed in to change notification settings - Fork 220
Fix goroutine leak: make flushDaemon stoppable #293
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
Changes from all commits
0d5c8b7
7ad18de
b6757a5
31a05ea
ec08484
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
|
||
"go.uber.org/goleak" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func main() { | ||
klog.InitFlags(nil) | ||
|
||
// By default klog writes to stderr. Setting logtostderr to false makes klog | ||
// write to a log file. | ||
flag.Set("logtostderr", "false") | ||
flag.Set("log_file", "myfile.log") | ||
flag.Parse() | ||
|
||
// Info writes the first log message. When the first log file is created, | ||
// a flushDaemon is started to frequently flush bytes to the file. | ||
klog.Info("nice to meet you") | ||
|
||
// klog won't ever stop this flushDaemon. To exit without leaking a goroutine, | ||
// the daemon can be stopped manually. | ||
klog.StopFlushDaemon() | ||
|
||
// After you stopped the flushDaemon, you can still manually flush. | ||
klog.Info("bye") | ||
klog.Flush() | ||
} | ||
|
||
func TestLeakingFlushDaemon(t *testing.T) { | ||
// goleak detects leaking goroutines. | ||
defer goleak.VerifyNone(t) | ||
|
||
// Without calling StopFlushDaemon in main, this test will fail. | ||
main() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ module k8s.io/klog/v2 | |
|
||
go 1.13 | ||
|
||
require github.com/go-logr/logr v1.2.0 | ||
require ( | ||
github.com/go-logr/logr v1.2.0 | ||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this adds a circular dependency... utils already depends on klog, we should avoid making klog also depend on utils There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the test is useful enough that we should not remove it and instead carry a copy of the clock code -> #310 |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= | ||
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE= | ||
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= | ||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc= | ||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= |
Uh oh!
There was an error while loading. Please reload this page.