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, made tests deterministic #1

Merged
merged 3 commits into from
Aug 10, 2020

Conversation

TimKingtonFC
Copy link
Collaborator

@TimKingtonFC TimKingtonFC commented Aug 6, 2020

This is based on howbazaar's changes with 4a6f656c's comments here: https://github.com/natefinch/lumberjack/pull/100/files
I changed a few things, too.

@@ -4,9 +4,9 @@ package lumberjack

import (
"os"
"sync"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What's the easiest way to test the linux version?

Choose a reason for hiding this comment

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

add a build tag for only running on linux (if necessary), then run on a linux machine (e.g. Jenkins)

@@ -408,10 +409,6 @@ func TestMaxAge(t *testing.T) {
equals(len(b2), n, t)
existsWithContent(backupFile(dir), b, t)

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

Choose a reason for hiding this comment

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

This was waiting for something that shouldn't happen. Now we'll get a deadlock in the test is there's an extra remove because nobody reads the notifyRemove chan.

@@ -559,35 +555,38 @@ func TestRotate(t *testing.T) {
err = l.Rotate()
isNil(err, t)

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

Choose a reason for hiding this comment

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

ditto

filename2 := backupFile(dir)
existsWithContent(filename2, b, t)
existsWithContent(filename, []byte{}, t)
fileCount(dir, 2, t)
newFakeTime()

b2 := []byte("bar")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added data so we can see if the files are rotated correctly.

example_test.go Outdated Show resolved Hide resolved
rotate_test.go Outdated Show resolved Hide resolved
@@ -165,6 +170,14 @@ func (l *Logger) Write(p []byte) (n int, err error) {
func (l *Logger) Close() error {
l.mu.Lock()
defer l.mu.Unlock()

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

Choose a reason for hiding this comment

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

this is the actual fix for the leak, right? (just making sure I grok it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

@connyay
Copy link

connyay commented Aug 6, 2020

Is this based on natefinch#100 ?

@TimKingtonFC
Copy link
Collaborator Author

Is this based on natefinch#100 ?

Yep. Added that to the description, but you were too fast for me.

@@ -4,9 +4,9 @@ package lumberjack

import (
"os"
"sync"

Choose a reason for hiding this comment

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

add a build tag for only running on linux (if necessary), then run on a linux machine (e.g. Jenkins)

lumberjack.go Outdated Show resolved Hide resolved
rotate_test.go Outdated Show resolved Hide resolved
example_test.go Outdated Show resolved Hide resolved
Copy link

@connyay connyay left a comment

Choose a reason for hiding this comment

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

Nice!

@connyay
Copy link

connyay commented Aug 10, 2020

@TimKingtonFC this good to land?

@TimKingtonFC
Copy link
Collaborator Author

Yes, but I haven't figured out how to run the linux tests.

@TimKingtonFC TimKingtonFC merged commit 1b9897e into v2.0 Aug 10, 2020
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.

3 participants