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

Handle vanishing PIDs #1043

Merged
merged 1 commit into from
Aug 13, 2018
Merged

Handle vanishing PIDs #1043

merged 1 commit into from
Aug 13, 2018

Conversation

SuperQ
Copy link
Member

@SuperQ SuperQ commented Aug 13, 2018

PIDs can vanish (exit) from /proc/ between gathering the list of PIDs
and getting all of their stats.

  • Ignore file not found errors.
  • Explicitly count the PIDs we find.
  • Cleanup some error style issues.

Fixes: #1042

Signed-off-by: Ben Kochie superq@gmail.com

@SuperQ SuperQ requested a review from discordianfish August 13, 2018 14:10
@SuperQ SuperQ force-pushed the superq/process_file_missing branch from ec73c90 to dc49974 Compare August 13, 2018 14:11
PIDs can vanish (exit) from /proc/ between gathering the list of PIDs
and getting all of their stats.
* Ignore file not found errors.
* Explicitly count the PIDs we find.
* Cleanup some error style issues.

Signed-off-by: Ben Kochie <superq@gmail.com>
@SuperQ SuperQ force-pushed the superq/process_file_missing branch from dc49974 to 0c42334 Compare August 13, 2018 14:12
@brian-brazil
Copy link
Contributor

👍

Copy link
Member

@discordianfish discordianfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SuperQ SuperQ merged commit fe5a117 into master Aug 13, 2018
@SuperQ SuperQ deleted the superq/process_file_missing branch August 13, 2018 15:27
thread := 0
procStates := make(map[string]int32)
for _, pid := range p {
stat, err := pid.NewStat()
// PIDs can vanish between getting the list and getting stats.
if os.IsNotExist(err) {
log.Debugf("file not found when retrieving stats: %q", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use %s or %v for error type formatting (but %q is good to quote file names embedded in a string).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an issue all over the codebase. I filed #1044 to do cleanup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like all the other %q I found are legit - %q makes sense when you actually want to quote something, but when you have a final colon and then an entire error string following, it doesn't make sense to quote that.

oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
PIDs can vanish (exit) from /proc/ between gathering the list of PIDs
and getting all of their stats.

* Ignore file not found errors.
* Explicitly count the PIDs we find.
* Cleanup some error style issues.

Signed-off-by: Ben Kochie <superq@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants