Skip to content

Commit

Permalink
Reduce errors on filebeat syslog stop (#8347)
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:
  • Loading branch information
jsoriano committed Sep 20, 2018
1 parent 4db5f0a commit 9b27040
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
- Mark the TCP and UDP input as GA. {pull}8125[8125]
- Fixed a docker input error due to the offset update bug in partial log join.{pull}8177[8177]
- Update CRI format to support partial/full tags. {pull}8265[8265]
- Fix some errors happening when stopping syslog input. {pull}8347[8347]

*Heartbeat*

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 9b27040

Please sign in to comment.