{"record":{"id":"684acd18efd1af97","repo":"prometheus/node_exporter","slug":"panic-err","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"collector/loadavg_solaris.go","lineNumber":32,"sourceCode":"//go:build !noloadavg\n\npackage collector\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\n\t\"github.com/illumos/go-kstat\"\n)\n\n// #include <sys/param.h>\nimport \"C\"\n\nfunc kstatToFloat(ks *kstat.KStat, kstatKey string) float64 {\n\tkstatValue, err := ks.GetNamed(kstatKey)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tkstatLoadavg, err := strconv.ParseFloat(\n\t\tfmt.Sprintf(\"%.2f\", float64(kstatValue.UintVal)/C.FSCALE), 64)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn kstatLoadavg\n}\n\nfunc getLoad() ([]float64, error) {\n\ttok, err := kstat.Open()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/loadavg_solaris.go#L14-L50","documentation":"kstatToFloat panics when ks.GetNamed(kstatKey) fails on the Solaris/illumos kstat \"unix:0:system_misc\" named statistic. GetNamed returns an error if the named kstat (e.g. avenrun_1min) does not exist or the kstat data could not be read; this collector turns that into an unrecoverable panic rather than an error, crashing the exporter's scrape goroutine.","triggerScenarios":"Calling getLoad -> kstatToFloat(ks, \"avenrun_1min\"/\"avenrun_5min\"/\"avenrun_15min\") on Solaris/illumos when the system_misc kstat lacks the requested avenrun_* named statistic or GetNamed cannot read the kstat value (kstat chain changed, snapshot failed, permission problem opening kstats).","commonSituations":"Running node_exporter in a Solaris zone/branded zone where system_misc avenrun kstats are not exposed; illumos distribution or kernel revision that renamed or dropped the avenrun_* named stats; kstat permissions restricting access to the unix:0:system_misc instance.","solutions":["Verify the kstat exists on the affected host: run `kstat -p unix:0:system_misc:avenrun_1min` and confirm output.","Run node_exporter in the global zone (or grant the zone access to system_misc kstats) so avenrun_* statistics are visible.","Patch kstatToFloat to return (float64, error) and propagate the error to getLoad instead of panicking.","Build with the -tags noloadavg build tag to exclude the loadavg collector if load average cannot be supported on the target platform."],"exampleFix":"// before\nfunc kstatToFloat(ks *kstat.KStat, kstatKey string) float64 {\n\tkstatValue, err := ks.GetNamed(kstatKey)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n// after\nfunc kstatToFloat(ks *kstat.KStat, kstatKey string) (float64, error) {\n\tkstatValue, err := ks.GetNamed(kstatKey)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"couldn't get kstat %s: %w\", kstatKey, err)\n\t}","handlingStrategy":"try-catch","validationCode":"// before scraping loadavg on Solaris/illumos\nout, err := exec.Command(\"kstat\", \"-p\", \"unix:0:system_misc:avenrun_1min\").Output()\nif err != nil || len(out) == 0 {\n\tlog.Println(\"avenrun_1min kstat not available; loadavg metrics disabled\")\n}","typeGuard":"func hasAvenrunKstat(ks *kstat.KStat) bool {\n\t_, err := ks.GetNamed(\"avenrun_1min\")\n\treturn err == nil\n}","tryCatchPattern":"// Go has no catch for panic; recover at the scrape boundary\nfunc safeGetLoad() (v []float64, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"loadavg kstat panic: %v\", r)\n\t\t}\n\t}()\n\treturn getLoad()\n}","preventionTips":["Run node_exporter in the global zone where avenrun_* kstats are guaranteed present.","Smoke-test `kstat -p unix:0:system_misc:avenrun_*` after kernel or zone upgrades.","Patch the collector to propagate errors instead of panicking (getLoad already returns error).","Build with -tags noloadavg on platforms lacking system_misc."],"tags":["solaris","illumos","kstat","panic","loadavg"],"backgroundTag":"internal-invariant-violation","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}