Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce errors on filebeat syslog stop #8347

Merged
merged 3 commits into from Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
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
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
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