Don't close connection if readTimeout exceeded

This commit is contained in:
Greg Linton 2018-07-02 18:56:58 -06:00
parent 58e815fdd1
commit a7545e6cac
1 changed files with 9 additions and 5 deletions

View File

@ -296,12 +296,16 @@ func (s *Syslog) handle(conn net.Conn, acc telegraf.Accumulator) {
// read to the tmp var // read to the tmp var
n, err := conn.Read(tmp) n, err := conn.Read(tmp)
if err != nil { if err != nil {
// Ignore known/recoverable errors. In contrived tests: // read timeout reached, retry
// * i/o timeout error - no data to Read() before s.ReadTimeout.Duration expired if er, ok := err.(net.Error); ok && er.Timeout() {
// * EOF error - connection open/close immediately continue
if er, ok := err.(net.Error); err != io.EOF && (ok && !er.Timeout()) {
s.store(rfc5425.Result{Error: fmt.Errorf("Failed reading from syslog client - %s", err.Error())}, acc)
} }
// client has closed connection, return
if err == io.EOF {
return
}
// other error, log and return
s.store(rfc5425.Result{Error: fmt.Errorf("failed reading from syslog client - %s", err.Error())}, acc)
return return
} }