protect writing to closed channel

This commit is contained in:
Alex Dadgar 2016-04-18 11:46:57 -07:00
parent 67865ab530
commit ebdc873e47

View file

@ -130,7 +130,9 @@ func (f *FileRotator) nextFile() error {
break
}
// Purge old files if we have more files than MaxFiles
if f.logFileIdx-f.oldestLogFileIdx >= f.MaxFiles {
f.closedLock.Lock()
defer f.closedLock.Unlock()
if f.logFileIdx-f.oldestLogFileIdx >= f.MaxFiles && !f.closed {
select {
case f.purgeCh <- struct{}{}:
default: