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 break
} }
// Purge old files if we have more files than MaxFiles // 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 { select {
case f.purgeCh <- struct{}{}: case f.purgeCh <- struct{}{}:
default: default: