From 99edca80ef4a418a5236c36c11b908c9ce503698 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Thu, 18 May 2017 18:03:54 -0700 Subject: [PATCH] Handle process termination during read from /proc (#2816) Fixes #2815. (cherry picked from commit c53d9fa9b760d1db9558f3b9b458e41e467dde70) --- CHANGELOG.md | 1 + plugins/inputs/system/processes.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b5176fe..c19fe4b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#2749](https://github.com/influxdata/telegraf/pull/2749): Fixed sqlserver input to work with case sensitive server collation. - [#2782](https://github.com/influxdata/telegraf/pull/2782): Reuse transports in input plugins +- [#2815](https://github.com/influxdata/telegraf/issues/2815): Inputs processes fails with "no such process". ## v1.3 [2017-05-15] 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 }