From b66e53a2ac9d0cedf4ae9d81d5cf3022fde66be3 Mon Sep 17 00:00:00 2001 From: Timo Mihaljov Date: Wed, 17 May 2017 03:33:35 +0300 Subject: [PATCH] Handle process termination during read from /proc (#2816) Fixes #2815. --- plugins/inputs/system/processes.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/inputs/system/processes.go b/plugins/inputs/system/processes.go index 202bdf058..09aa37afb 100644 --- a/plugins/inputs/system/processes.go +++ b/plugins/inputs/system/processes.go @@ -12,6 +12,7 @@ import ( "path/filepath" "runtime" "strconv" + "syscall" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" @@ -195,6 +196,13 @@ func readProcFile(filename string) ([]byte, error) { if os.IsNotExist(err) { return nil, nil } + + // Reading from /proc/ fails with ESRCH if the process has + // been terminated between open() and read(). + if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ESRCH { + return nil, nil + } + return nil, err }