shirou / gopsutil

psutil for golang
Other
10.68k stars 1.59k forks source link

sensors.TemperaturesWithContext() crashes on darwin arm64 #1726

Closed sni closed 1 month ago

sni commented 1 month ago

Describe the bug calling sensors.TemperaturesWithContext(ctx) crashes with sigsegv

To Reproduce

sensors.TemperaturesWithContext(context.TODO())

Expected behavior I would not expect it to crash obviously

Environment (please complete the following information):

Happens on the github darwin runner which reports as:

Current runner version: '2.319.1'
Operating System
  macOS
  14.6.1
  23G93
Runner Image
  Image: macos-14-arm64
  Version: 20240922.1

using go:
go version go1.22.7 darwin/arm64

Additional context

I am a but curious why it calls runtime.cgocall() in the end if this version should be without cgo?

Here is the relevant part of the crash output:

SIGSEGV: segmentation violation
PC=0x195daf738 m=8 sigcode=2 addr=0x0
signal arrived during cgo execution

goroutine 22 gp=0x140002501c0 m=8 mp=0x1400006c408 [syscall]:
runtime.cgocall(0x102c775f0, 0x140004b6ea0)
/Users/runner/hostedtoolcache/go/1.22.7/arm64/src/runtime/cgocall.go:157 +0x44 fp=0x140003101c0 sp=0x14000310180 pc=0x102955944
    github.com/ebitengine/purego.RegisterFunc.func4({0x14000494438?, 0x1?, 0x1?})
/Users/runner/go/pkg/mod/github.com/ebitengine/purego@v0.8.0/func.go:320 +0x938 fp=0x14000310640 sp=0x140003101c0 pc=0x102c74208
    reflect.callReflect(0x14000469d70, 0x14000310c18, 0x14000310a78, 0x14000310a80)
/Users/runner/hostedtoolcache/go/1.22.7/arm64/src/reflect/value.go:782 +0x3e8 fp=0x14000310a20 sp=0x14000310640 pc=0x1029fb7a8
    reflect.callReflect(0x14000469d70, 0x14000310c18, 0x14000310a78, 0x14000310a80)
<autogenerated>:1 +0x28 fp=0x14000310a50 sp=0x14000310a20 pc=0x102a0bcd8
    reflect.makeFuncStub()
/Users/runner/hostedtoolcache/go/1.22.7/arm64/src/reflect/asm_arm64.s:48 +0x58 fp=0x14000310c10 sp=0x14000310a50 pc=0x102a07ce8
    github.com/shirou/gopsutil/v4/sensors.(*temperatureArm).getProductNames(0x14000311058)
/Users/runner/go/pkg/mod/github.com/shirou/gopsutil/v4@v4.24.9/sensors/sensors_darwin_arm64.go:99 +0x184 fp=0x14000310d20 sp=0x14000310c10 pc=0x102d0f624
    github.com/shirou/gopsutil/v4/sensors.TemperaturesWithContext({0x1038c5be0?, 0x103a985e0?})
/Users/runner/go/pkg/mod/github.com/shirou/gopsutil/v4@v4.24.9/sensors/sensors_darwin_arm64.go:44 +0x33c fp=0x140003111c0 sp=0x14000310d20 pc=0x102d0f02c

(full log is here: https://github.com/ConSol-Monitoring/snclient/actions/runs/11215929181/job/31174213915#step:5:376)

Besides that, i am unable to reproduce it on my m1 mac which is the only mac which i have my hands on.

From a quick search i did not find any unit tests for the actual sensors packages (just a string format test) I added a unit test: https://github.com/shirou/gopsutil/pull/1725 to see if it crashes here as well.