natefinch/lumberjack

goroutine leak

jaczhao opened this issue · 3 comments

millrun goroutine leak.

I use zap to wrap lumberjack, my code is following

w := zapcore.AddSync(&lumberjack.Logger{
  Filename:   "/var/log/myapp/foo.log",
  MaxSize:    500, // megabytes
  MaxBackups: 3,
  MaxAge:     28, // days
})
core := zapcore.NewCore(
  zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
  w,
  zap.InfoLevel,
)
logger := zap.New(core)

when I do testing, I got the following error:

Too many goroutines running after all test(s).
1 instances of:

**/vendor/gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun(...)
**/vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go:379 +0x58
created by **/vendor/gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1
***/vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go:390 +0x7e
ERROR: *manager.**TestSuite is failed by leak goroutine check.

I tried to used Close() method, but it still failed.

I read source code and fount that nowhere to close the logger.millCh, so this goroutine will live forever.

You're right that we do have a Close method, and that close method could stop the mill goroutine fairly trivially. I'll get that fix out sometime soon, or you're welcome to send in a PR :)

one PR, please review it, Thanks

Experiencing the same issue . Thanks @jaczhao for the solution.