Skip to content

Commit

Permalink
Reduce errors on filebeat syslog stop (#8347) (#8377)
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 Sep 24, 2018
1 parent 4b809aa commit 15d4139
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ https://github.com/elastic/beats/compare/v6.4.1...6.4[Check the HEAD diff]

*Filebeat*

- Fix some errors happening when stopping syslog input. {pull}8347[8347]

*Heartbeat*

*Metricbeat*
Expand Down
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 15d4139

Please sign in to comment.