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

Ensure that the millRun goroutine terminates when Close called. #211

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

Conversation

SimonRichardson
Copy link

This is an attempt to upstream and complete the patch that @howbazaar started a couple of years ago.

The motivation for this patch is to move back to tracking upstream rather than an independent fork.

The original description and PR #100:

Currently the millRun goroutines leaks. This is very noticeable if
a Logger is constructed periodically, used and then closed.
This change ensures that the millCh channel is closed if it exists.
Existing log rotation tests cover the duplicate Close calls.

howbazaar and others added 4 commits May 24, 2024 09:58
Currently the millRun goroutines leaks. This is very noticable if
a Logger is constructed periodically, used and then closed.

This change ensures that the millCh channel is closed if it exists.
While fixing the tests I noticed that the original patch closed the millRun goroutine in the wrong place. I didn't realise that the `close` method was called internally as well as part of the `rotate` method. The closing of the mill signalling channel is now done in the `Close` method.

There were a bunch of race errors detected, mostly around the updating of the time, and the `fakeFS`. Synchronisation is added to these.

All of the `time.After` calls have been removed from the tests and the execution time has gone from 700ms to 7ms on my machine.

Two different notify channels were added to the `Logger` internals. These are only ever set in the tests, and no notification is done for any normal `Logger` use. In order to avoid spurious errors the `Close` method needed to wait for the `millRun` goroutine to complete, otherwise there was potential for the `millRunOnce` method to return errors. I temporarily added a panic to that method while testing. I use a wait group to wait for the goroutine to be complete. However due to the way the `sync.WaitGroup` works, you can't reuse them, so we have a pointer to a `sync.WaitGroup`.

This patch does introduce a change in behaviour, which is in evidence due to the deleted test. Effectively I was left with two choices: allow the compression of existing old log files as part of writing to a new logger (which wouldn't rotate the files yet); or have a race in the `TestCleanupExistingBackups`. This test failure was intermittent, due to the race. I decided on determinism as the likelihood of having old uncompressed files around that needed to be compressed was small.
As feedback from a code review, use the struct channels as a way
of self documenting the code. This makes the code more readable.
@john8329
Copy link

john8329 commented Aug 12, 2024

This is a pretty important resource leak, @natefinch can you please take a look? I'm experiencing the same issue, no matter if I close the logger or not.

Also this is related #205

Thanks

@john8329
Copy link

Also this #57 this #80 and this #90 among others, this is getting worrisome, is this library maintained?

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