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

fixed goroutine leak #57

Open
wants to merge 2 commits into
base: v2.0
Choose a base branch
from
Open

Conversation

jaczhao
Copy link

@jaczhao jaczhao commented Nov 3, 2017

I consider the Close() method is finalize call, so I make close(chan) call. the relate issue #56


if l.millCh != nil {
close(l.millCh)
l.wg.Wait()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after waiting, you need to set millCh to nil, so if someone calls close again, it won't panic, trying to close the same channel.

Copy link
Author

@jaczhao jaczhao Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are righ

@@ -112,6 +112,7 @@ type Logger struct {
mu sync.Mutex

millCh chan bool
wg sync.WaitGroup
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a pointer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? it would not be passed by method, just one property of this struct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natefinch could you reply this?

Copy link

@gz-c gz-c Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaczhao
https://golang.org/pkg/sync/#WaitGroup

A WaitGroup must not be copied after first use.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so where to init the : wg sync.WaitGroup

temporary I put it in file : lumberjack.go

// mill performs post-rotation compression and removal of stale log files,
// starting the mill goroutine if necessary.
func (l *Logger) mill() {
	if l.wg == nil {
		l.wg = new(sync.WaitGroup)
	}

	l.startMill.Do(func() {
		l.wg.Add(1)
		l.millCh = make(chan bool, 1)
		go l.millRun()
	})
	select {
	case l.millCh <- true:
	default:
	}
}

@@ -623,7 +623,7 @@ func TestCompressOnRotate(t *testing.T) {

// we need to wait a little bit since the files get compressed on a different
// goroutine.
<-time.After(10 * time.Millisecond)
<-time.After(20 * time.Millisecond)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you need to up these to make the tests pass? Just curious

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I would got random failed if only 5 seconds

@natefinch
Copy link
Owner

natefinch commented Nov 20, 2017 via email

@brunoamancio
Copy link

@natefinch any news?

@natefinch
Copy link
Owner

I'll have to refresh myself on this. I think it's probably fine, but I want to make sure. Most people just start one logger and let.it run for the lifetime of the process. But if we can make it clean up better, that's definitely a good thing.

@natefinch
Copy link
Owner

This still needs a couple updates as specified above. I'll do the work myself if @jaczhao isn't interested anymore (not anyone's fault, it's been forever).

@nmiyake
Copy link

nmiyake commented Mar 15, 2019

@natefinch or @jaczhao any plans on picking this up? I'm running into this now as well. If I don't hear an ACK, will post a new PR that picks up where this left off (will be based on this one and implement the feedback)

@nmiyake
Copy link

nmiyake commented Mar 15, 2019

Opened #80 as a PR that implements the requested changes to this PR and also adds a test.

@howbazaar
Copy link

I also opened #100 to address this issue. My PR also fixes the test synchronisation and determinism.

@CaledoniaProject
Copy link

Interesting, such a big and obvious bug, and this is still not merged after 3 years.

@natefinch
Copy link
Owner

It's not a big bug, since you don't normally restart your logging infrastructure multiple times. But you're right that it should get merged.

@CaledoniaProject
Copy link

It's a big bug to me. I have a program with multiple goroutines that each of them writes to a different log file.

@Onine0811
Copy link

Onine0811 commented Mar 3, 2023

so cool, the bug has not been fixed yet.

@gregtwallace
Copy link

Onine0811

Unfortunately not it seems.

@chensmiles
Copy link

@natefinch any new plans about this bug? there has already 3 PRs , will anyone get merged?

@CaledoniaProject
Copy link

We should create a new repo and dispose this one.

djaglowski pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Jan 31, 2024
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This enables `goleak` to check for any leaking goroutines in this
package. There is an existing goleak, but it's in a third party
dependency which we cannot resolve on our end. There's been a [PR open
for this issue](natefinch/lumberjack#57) for 6
years and it hasn't been merged.

**Note:** The `natefinch/lumberjack` package is now unmaintained, so
this will likely never be fixed. We should consider moving to a new
package if possible to avoid the leak. I'll defer to code owners for
feedback on possible options.

**Link to tracking Issue:** <Issue number if applicable>
#30438

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added goleak check are passing.
cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this pull request Feb 1, 2024
)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This enables `goleak` to check for any leaking goroutines in this
package. There is an existing goleak, but it's in a third party
dependency which we cannot resolve on our end. There's been a [PR open
for this issue](natefinch/lumberjack#57) for 6
years and it hasn't been merged.

**Note:** The `natefinch/lumberjack` package is now unmaintained, so
this will likely never be fixed. We should consider moving to a new
package if possible to avoid the leak. I'll defer to code owners for
feedback on possible options.

**Link to tracking Issue:** <Issue number if applicable>
open-telemetry#30438

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added goleak check are passing.
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.