shirou / gopsutil

psutil for golang
Other
10.28k stars 1.56k forks source link

AIX Runtime Panic in Host #1661

Closed aidangill-projects closed 3 weeks ago

aidangill-projects commented 1 month ago

Describe the bug

I can't reproduce this, but I have gotten a few runtime panics with the following:

panic: runtime error: index out of range [1] with length 1

goroutine 66 [running]:
github.com/shirou/gopsutil/v4/host.UptimeWithContext({0x1003a53a0?, 0x11011edc0?})
        /home/runner/go/pkg/mod/github.com/shirou/gopsutil/v4@v4.24.5/host/host_aix.go:80 +0x510
github.com/shirou/gopsutil/v4/host.BootTimeWithContext({0x1003a53a0?, 0x11011edc0?})
        /home/runner/go/pkg/mod/github.com/shirou/gopsutil/v4@v4.24.5/host/host_aix.go:35 +0x3c github.com/shirou/gopsutil/v4/host.InfoWithContext({0x1003a53a0, 0x11011edc0})
        /home/runner/go/pkg/mod/github.com/shirou/gopsutil/v4@v4.24.5/host/host.go:96 +0x2d8 github.com/shirou/gopsutil/v4/host.Info(...)
        /home/runner/go/pkg/mod/github.com/shirou/gopsutil/v4@v4.24.5/host/host.go:62 main.getInfo()
        /home/runner/work/goagent/goagent/server_details.go:80 +0x38 main.getSystemInfo({0xa00010000482000, 0x14})
        /home/runner/work/goagent/goagent/server_details.go:46 +0x40 main.monitorThread()
        /home/runner/work/goagent/goagent/monitor_thread.go:12 +0x38 created by main.main in goroutine 1
        /home/runner/work/goagent/goagent/main.go:35 +0x248

While uptime returns:

# uptime
  06:48PM   up 2 days,  18:01,  1 user,  load average: 1.93, 2.02, 2.11

Which seems to be this line:

minutes, err = strconv.ParseUint(strings.Replace(hm[1], ",", "", -1), 10, 64)

If I see this again I will update + provide a fix

Environment (please complete the following information):

AIX PPC64

aidangill-projects commented 1 month ago

It seems at exactly zero minutes, it returns 'X hrs', not X:00 - silly huh:

2024/06/06 01:47:12 08:47PM up 2 days, 20 hrs, 1 user, load average: 2.47, 2.17, 2.17 panic: runtime error: index out of range [1] with length 1

I will resolve and create a pull request

Lomanic commented 3 weeks ago

Fixed in #1663