Skip to content

Flaky panic on macOS: unsafe.Slice: ptr is nil and len is not zero in perCPUTimes #1834

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

Closed
dvovk opened this issue Apr 7, 2025 · 2 comments

Comments

@dvovk
Copy link
Contributor

dvovk commented Apr 7, 2025

Hi 👋

We’re encountering a flaky runtime panic on macOS systems when calling cpu.Times() from github.com/shirou/gopsutil/[email protected]. The panic looks like this:

panic: runtime error: unsafe.Slice: ptr is nil and len is not zero

goroutine 1 [running]:
github.com/shirou/gopsutil/v4/cpu.perCPUTimes(0x14000a37660)
	github.com/shirou/gopsutil/[email protected]/cpu/cpu_darwin.go:158 +0x4ec
github.com/shirou/gopsutil/v4/cpu.TimesWithContext({0x104548ae0?, 0x1400002d110?}, 0x1)
	github.com/shirou/gopsutil/[email protected]/cpu/cpu_darwin.go:70 +0x70
github.com/shirou/gopsutil/v4/cpu.Times(...)
	github.com/shirou/gopsutil/[email protected]/cpu/cpu_darwin.go:59
github.com/shirou/gopsutil/v4/cpu.init.0()

This seems related to changes introduced in v4.24.9, which updated the macOS CPU code to use unsafe.Slice.

Reproducibility

This happens intermittently — we’ve seen it in CI or test environments on macOS. Runner details https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md

@dvovk dvovk mentioned this issue Apr 7, 2025
@dvovk
Copy link
Contributor Author

dvovk commented Apr 7, 2025

This one may solve the issue #1835

@shirou
Copy link
Owner

shirou commented Apr 15, 2025

Since #1835 has been merged, I close this issue. If the panic still happen, feel free to re-open this issue. Thank you for your contribution!

@shirou shirou closed this as completed Apr 15, 2025
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

No branches or pull requests

2 participants