From f6b3759a74e150e31e321e4dcee328972065094b Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 16 Oct 2018 16:55:43 +0200 Subject: [PATCH] Reduce errors on filebeat syslog stop (#8347) (#8376) Fix a couple of errors seen when syslog input is stopped. In case the input couldn't be started (e.g. port was already in use), there was a nil pointer reference error when trying to stop it. In any case, on stop, an error about use of closed connection was logged lots of times: (cherry picked from commit 9b270401833a56258bc1817eb373d7c07515a4cf) --- filebeat/input/syslog/input.go | 5 +++++ filebeat/inputsource/udp/server.go | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/filebeat/input/syslog/input.go b/filebeat/input/syslog/input.go index d8f7dde529a..29b2325359f 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 762e927a89b..c263a2ca4e8 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") }