Skip to content
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

goroutine leak in package detected #182

Open
crobert-1 opened this issue Jan 12, 2024 · 2 comments
Open

goroutine leak in package detected #182

crobert-1 opened this issue Jan 12, 2024 · 2 comments

Comments

@crobert-1
Copy link

Context
Hello, I'm currently working on open-telemetry/opentelemetry-collector-contrib#30438 to enable goleak to check for leaked goroutines.

Bug
Here's the goleak output for the leaking goroutine:

[Goroutine 13 in state sync.Cond.Wait, with sync.runtime_notifyListWait on top of the stack:
sync.runtime_notifyListWait(0xc002140d10, 0x0)
        /usr/local/Cellar/go/1.21.0/libexec/src/runtime/sema.go:527 +0x159
sync.(*Cond).Wait(0x0?)
        /usr/local/Cellar/go/1.21.0/libexec/src/sync/cond.go:70 +0x85
github.com/cihub/seelog.(*asyncLoopLogger).processItem(0xc0020e46c0)
        /Users/crobert/go/pkg/mod/github.com/cihub/[email protected]/behavior_asynclooplogger.go:50 +0x99
github.com/cihub/seelog.(*asyncLoopLogger).processQueue(0xc0020e46c0)
        /Users/crobert/go/pkg/mod/github.com/cihub/[email protected]/behavior_asynclooplogger.go:63 +0x33
created by github.com/cihub/seelog.NewAsyncLoopLogger in goroutine 1
        /Users/crobert/go/pkg/mod/github.com/cihub/[email protected]/behavior_asynclooplogger.go:40 +0xcf

Here's the line that causing it:

go asnLoopLogger.processQueue()

This call is happening on init(), which means the goroutine is started when a package is imported, even if it isn't used.

Solution
It's generally not good practice to start a goroutine in init. The best solution here would only be start the goroutine when required, and provide a public API to stop it.

Related:
#86

@songy23
Copy link

songy23 commented Jul 11, 2024

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

No branches or pull requests

2 participants