natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.8k stars 591 forks source link

lumberjack has increasing number of file descriptors open for the same logfile #61

Closed ermalguni closed 6 years ago

ermalguni commented 6 years ago

I am using lumberjack in conjunction with zerolog like this:

logRotator := lumberjack.Logger{
        Filename:   "/tmp/logging.log",
        MaxBackups: 7,
        MaxSize:    500,
        MaxAge:     10,
    }

log := zerolog.New(&logRotator).Timestamp().Logger()

After checking the open files I see that the number of file descriptors is always increasing until it hit the max and you cannot do anything with the system.

This is what I get after (around) 4mins.

$ lsof | grep logging | wc -l
19374
natefinch commented 6 years ago

Lumberjack is used in production in a lot of services. File descriptors have never been a problem before. The file is held open by lumberjack and closed as needed for rotation.

I think the problem must be somewhere else in your code. Are you sure you're not calling this code multiple times? Lumberjack is not idempotent, it's up to you to make sure there's only one instance of the lumberjack Logger in your system.

ermalguni commented 6 years ago

Sorry for the late reply. You are totally right. I found the bug a few days ago, lumberjack was wrongly initialized in a goroutine :( . Closing this.