Skip to content

fix🐛: stop Apple Silicon startup crash from go-m1cpu - #969

Open
fengyikang88 wants to merge 1 commit into
go-admin-team:masterfrom
fengyikang88:fix/apple-silicon-go-m1cpu-crash
Open

fengyikang88 wants to merge 1 commit into
go-admin-team:masterfrom
fengyikang88:fix/apple-silicon-go-m1cpu-crash

Conversation

@fengyikang88

Copy link
Copy Markdown

🤔 This is a ...

  • Bug fix

🔗 Related issue link

No existing issue. Reproduced locally on Apple Silicon while starting the backend from GoLand.

💡 Background and solution

On newer Apple Silicon machines the process dies during package initialization, before main runs:

SIGSEGV: segmentation violation
signal arrived during cgo execution
github.com/shoenig/go-m1cpu._Cfunc_initialize()
github.com/shoenig/go-m1cpu.init.0()
    github.com/shoenig/go-m1cpu@v0.1.6/cpu.go:148

go-m1cpu v0.1.6 reads the voltage-states*-sram IOKit property inside init() and dereferences it when the property is missing. That property is absent on newer chips (reproduced here on an M6 running macOS / Darwin 27), so every binary that imports the package crashes at startup. The variable length array folded to constant array lines printed just before the crash are only cgo warnings.

Two dependencies pull that package in:

  • The server monitor imported github.com/shirou/gopsutil/v3 directly.
  • github.com/alibaba/sentinel-golang still imports gopsutil/v3 for system metrics, and v3 is frozen on go-m1cpu v0.1.6. Switching only our own imports is not enough.

Changes:

  • Move app/other/apis/sys_server_monitor.go to github.com/shirou/gopsutil/v4 (v4.26.9). The cpu, mem, disk, host, and net calls used here keep the same signatures, and v4 no longer depends on go-m1cpu.
  • Select github.com/shoenig/go-m1cpu v0.2.4 for the copy that sentinel-golang still imports through gopsutil/v3. v0.2.4 checks for a missing IOKit property and initializes lazily instead of crashing in init().

Verified on this machine with CGO_ENABLED=1:

  • go build succeeds.
  • go-admin version prints 2.4.0 instead of aborting in go-m1cpu.init.
  • cpu.Info() together with the Sentinel system metric import returns without a segmentation fault.

📝 Changelog

Language Changelog
🇺🇸 English Fix a startup crash on newer Apple Silicon caused by go-m1cpu v0.1.6 dereferencing a missing IOKit property during cgo init.
🇨🇳 Chinese 修复较新的 Apple Silicon 上,go-m1cpu v0.1.6 在 cgo 初始化时解引用缺失的 IOKit 属性,导致进程在进入 main 之前段错误退出的问题。

☑️ Self-Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript's definition is updated/provided or not needed
  • Changelog is provided or not needed

Made with Cursor

gopsutil v3 pulls go-m1cpu v0.1.6, whose cgo init dereferences a missing IOKit property on newer Apple Silicon and aborts the process before main.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant