Handle process termination during read from /proc (#2816)

Fixes #2815.
This commit is contained in:
Timo Mihaljov 2017-05-17 03:33:35 +03:00 committed by Daniel Nelson
parent ac5ac3161f
commit c53d9fa9b7
1 changed files with 8 additions and 0 deletions

View File

@ -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/<PID> 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
}