golang/go

runtime: bypass reading /proc/self/cgroup and /proc/self/mountinfo when GODEBUG=containermaxprocs=0

開放

#77,911 建立於 2026年3月3日

 (17 則留言) (1 個反應) (0 位負責人)Go (19,008 個分叉)batch import

倉庫指標

星標
 (133,883 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Hello,

The container-aware GOMAXPROCS that was introduced in go1.25 tries to read /proc/self/cgroup and /proc/self/mountinfo at startup.

These reads cause permission denials, when Go binaries built using go1.25 or later are run in a confined environment like snaps. Looking at the init function defaultGOMAXPROCSinit, I can see that /proc/self/cgroup and /proc/self/mountinfo are read unconditionally.

The GOMAXPROCS documentation shows that setting GODEBUG=containermaxprocs=0 and GODEBUG=updatemaxprocs=0 should disable context aware GOMAXPROCS and use runtime.NumCPU as the default value for the number of CPUs. However, since cgroup.OpenCPU runs every time on startup, we do not have an effective way to bypass this behavior using GODEBUG environment variables.

Would it be possible to allow for GODEBUG=containermaxprocs=0 to completely bypass the file reads and use runtime.NumCPU instead?

Thank you!

貢獻者指南