Merge pull request #961 from hashicorp/executor-tests

Making the calls to exit idempotent
This commit is contained in:
Diptanu Choudhury 2016-03-22 12:27:37 -07:00
commit 2ab8ab7789
2 changed files with 25 additions and 5 deletions

View file

@ -10,6 +10,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
)
@ -35,6 +36,9 @@ type FileRotator struct {
logger *log.Logger
purgeCh chan struct{}
doneCh chan struct{}
closed bool
closedLock sync.Mutex
}
// NewFileRotator returns a new file rotator
@ -194,6 +198,9 @@ func (f *FileRotator) flushPeriodically() {
}
func (f *FileRotator) Close() {
f.closedLock.Lock()
defer f.closedLock.Unlock()
// Stop the ticker and flush for one last time
f.flushTicker.Stop()
if f.bufw != nil {
@ -201,8 +208,11 @@ func (f *FileRotator) Close() {
}
// Stop the purge go routine
f.doneCh <- struct{}{}
close(f.purgeCh)
if !f.closed {
f.doneCh <- struct{}{}
close(f.purgeCh)
f.closed = true
}
}
// purgeOldFiles removes older files and keeps only the last N files rotated for

View file

@ -6,6 +6,7 @@ import (
"bufio"
"log"
"net"
"sync"
)
// SyslogServer is a server which listens to syslog messages and parses them
@ -14,7 +15,10 @@ type SyslogServer struct {
messages chan *SyslogMessage
parser *DockerLogParser
doneCh chan interface{}
doneCh chan interface{}
done bool
doneLock sync.Mutex
logger *log.Logger
}
@ -71,6 +75,12 @@ func (s *SyslogServer) read(connection net.Conn) {
// Shutdown shutsdown the syslog server
func (s *SyslogServer) Shutdown() {
close(s.doneCh)
close(s.messages)
s.doneLock.Lock()
s.doneLock.Unlock()
if !s.done {
close(s.doneCh)
close(s.messages)
s.done = true
}
}