Merge pull request #2937 from hashicorp/b-leak-plugin

Fix leaked plugin files for syslog server
This commit is contained in:
Alex Dadgar 2017-07-31 10:38:04 -07:00 committed by GitHub
commit 0a75fe53b6
1 changed files with 9 additions and 2 deletions

View File

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