fix: properly close millCh if non-nil.#7
Conversation
chancez
left a comment
There was a problem hiding this comment.
I don't think this is quite right either. close is called by rotate() which closes the file and opens a new one, then calls mill() which sends on millCh, which will now be empty. It's not re-created because millCh is only allocated once, using a sync.Once in mill: https://github.com/cilium/lumberjack/blob/master/lumberjack.go#L412-L415
So with this change, I'd expect that a rotation would result in the channel being closed, then a send on a nil channel would occur.
Besides this, this causes millRun to return, and never gets restarted.
|
Uh, you are right! Let me move it to |
552d0ee to
17aaef4
Compare
|
I think this looks correct, but would be able to add some tests that would cause the failure you originally saw in Tetragon and after this change, the test should pass? |
|
@chancez can i bump the go version to make use of Otherwise i could manually check number of goroutines in the test, eg: |
|
|
Also, add a millWg to properly wait for `millRun` goroutine to cleanly exit in `Close()`. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Playing with cilium/tetragon#4508 (and specifically writing the test for the exporter), i stumbled upon natefinch#219 (there are many reports: natefinch#205); that's because i am specifically testing that updating the
rotationIntervaldoes the trick and to do so, i usesynctest.Run()with some sleeps.The test failure:
If i manually update lumberjack code to close
millCh, the test passes without panic'ing.Here is the fix.