Fix leaked plugin files for syslog server

This PR fixes a leaking of the unix socket used when launching a syslog
server for the Docker driver.

Fixes https://github.com/hashicorp/nomad/issues/2844
This commit is contained in:
Alex Dadgar 2017-07-30 17:51:38 -07:00
parent d778d9d566
commit 010567dba8
1 changed files with 9 additions and 2 deletions

View File

@ -37,11 +37,17 @@ func (s *SyslogServer) Start() {
for {
select {
case <-s.doneCh:
s.listener.Close()
return
default:
connection, err := s.listener.Accept()
if err != nil {
s.doneLock.Lock()
done := s.done
s.doneLock.Unlock()
if done {
return
}
s.logger.Printf("[ERR] logcollector.server: error in accepting connection: %v", err)
continue
}
@ -74,11 +80,12 @@ func (s *SyslogServer) read(connection net.Conn) {
// Shutdown shutsdown the syslog server
func (s *SyslogServer) Shutdown() {
s.doneLock.Lock()
s.doneLock.Unlock()
defer s.doneLock.Unlock()
if !s.done {
close(s.doneCh)
close(s.messages)
s.done = true
s.listener.Close()
}
}