-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(collector/pcidevice): Add nil checks to prevent panic #3421
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
Conversation
Signed-off-by: Tiger1218 <[email protected]>
f19e494 to
11bd515
Compare
|
I have also encountered this panic error. In my case, I've got the following stack trace: The issue occurs in my environment where This PR's fix addresses exactly what I'm experiencing. |
| var maxLinkWidth, currentLinkWidth float64 | ||
|
|
||
| if device.MaxLinkSpeed != nil { | ||
| maxLinkSpeedTS = float64(int64(*device.MaxLinkSpeed * 1e9)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will emit a 0 for metrics we don't know the value for.
I think we should do something like this:
| maxLinkSpeedTS = float64(int64(*device.MaxLinkSpeed * 1e9)) | |
| ch <- c.descs[0].mustNewConstMetric(maxLinkSpeedTS, device.Location.Strings()...) |
SuperQ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rebase.
SuperQ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs rebase
|
I'm also cleaning up this collector in #3448. @Tiger1218 Would you mind taking a look at that to make sure I don't reintroduce bugs? 😹 |
The pcidevice collector panics with a "nil pointer dereference" error
on some systems. This occurs when a PCI device lacks certain attributes
in sysfs, such as 'current_link_speed' or 'current_link_width'.
The collector's Update method attempted to dereference these pointers
without verifying if they were nil, leading to a crash.
This commit introduces checks to verify that the link speed and width
pointers are not nil before they are dereferenced. If an attribute is
missing for a device, its corresponding metric will now be reported as 0,
making the collector more robust and preventing node_exporter from
crashing.