Merge pull request #961 from hashicorp/executor-tests
Making the calls to exit idempotent
This commit is contained in:
commit
2ab8ab7789
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue