Skip to content

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

@PrinsonF77

Description

@PrinsonF77

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions