Skip to content

Commit

Permalink
Reduce errors on filebeat syslog stop (#8347) (#8376)
Browse files Browse the repository at this point in the history
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 9b27040)
  • Loading branch information
jsoriano authored Oct 16, 2018
1 parent 4524f2a commit f6b3759
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions filebeat/input/syslog/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions filebeat/inputsource/udp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
}
Expand Down

0 comments on commit f6b3759

Please sign in to comment.