diff --git a/filebeat/input/syslog/input.go b/filebeat/input/syslog/input.go index d8f7dde529a3..29b2325359fa 100644 --- a/filebeat/input/syslog/input.go +++ b/filebeat/input/syslog/input.go @@ -174,6 +174,7 @@ func (p *Input) Run() { err := p.server.Start() if err != nil { p.log.Error("Error starting the server", "error", err) + return } p.started = true } @@ -185,6 +186,10 @@ func (p *Input) Stop() { p.Lock() defer p.Unlock() + if !p.started { + return + } + p.log.Info("Stopping Syslog input") p.server.Stop() p.started = false diff --git a/filebeat/inputsource/udp/server.go b/filebeat/inputsource/udp/server.go index 762e927a89bf..c263a2ca4e8a 100644 --- a/filebeat/inputsource/udp/server.go +++ b/filebeat/inputsource/udp/server.go @@ -96,7 +96,15 @@ func (u *Server) run() { continue } - u.log.Errorw("Error reading from the socket", "error", err) + // Closed network error string will never change in Go 1.X + // https://github.com/golang/go/issues/4373 + opErr, ok := err.(*net.OpError) + if ok && strings.Contains(opErr.Err.Error(), "use of closed network connection") { + u.log.Info("Connection has been closed") + return + } + + u.log.Errorf("Error reading from the socket %s", err) // On Windows send the current buffer and mark it as truncated. // The buffer will have content but length will return 0, addr will be nil. @@ -115,8 +123,8 @@ func (u *Server) run() { // Stop stops the current udp server. func (u *Server) Stop() { u.log.Info("Stopping UDP server") - u.Listener.Close() close(u.done) + u.Listener.Close() u.wg.Wait() u.log.Info("UDP server stopped") }