From 010567dba826345f001930a89cd8fe5339b30b89 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Sun, 30 Jul 2017 17:51:38 -0700 Subject: [PATCH] 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 --- client/driver/logging/syslog_server.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/driver/logging/syslog_server.go b/client/driver/logging/syslog_server.go index f059ef77b..5b9c5f40f 100644 --- a/client/driver/logging/syslog_server.go +++ b/client/driver/logging/syslog_server.go @@ -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() } }