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

Commits on May 24, 2024

  1. Ensure that the millRun goroutine terminates when Close called.

    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.
    howbazaar authored and SimonRichardson committed May 24, 2024
    Configuration menu
    Copy the full SHA
    48d4877 View commit details
    Browse the repository at this point in the history
  2. Fix the test synchronisation and race errors.

    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.
    howbazaar authored and SimonRichardson committed May 24, 2024
    Configuration menu
    Copy the full SHA
    1524e41 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0dc8bb3 View commit details
    Browse the repository at this point in the history
  4. Use internal channels

    As feedback from a code review, use the struct channels as a way
    of self documenting the code. This makes the code more readable.
    SimonRichardson committed May 24, 2024
    Configuration menu
    Copy the full SHA
    012c0c2 View commit details
    Browse the repository at this point in the history