Skip to content
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

feat: add nocgroup build tag for systems without cgroup #3948

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

AlexLast
Copy link
Contributor

@AlexLast AlexLast commented Mar 1, 2024

In restricted environments, for example some PaaS, there is limited/no access to Linux cgroups. This can cause the following panic:

[2024-02-29 21:10:43] {"@timestamp":"2024-02-29T21:10:43.134Z","content":"cannot statfs cgroup root: no such file or directory
goroutine 4 [running]:
runtime/debug.Stack()
    /layers/heroku_go/shim/go1.21.6/go/src/runtime/debug/stack.go:24 +0x5e
github.com/zeromicro/go-zero/core/logx.writeStack({0xc00012c4c0, 0x34})
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/logx/logs.go:521 +0x34
github.com/zeromicro/go-zero/core/logx.ErrorStack({0xc000080b80?, 0xc000080c60?, 0xc000080c28?})
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/logx/logs.go:126 +0x2a
github.com/zeromicro/go-zero/core/rescue.Recover({0x0, 0x0, 0x8?})
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/rescue/recover.go:20 +0x76
panic({0x11bda20?, 0xc0002b0070?})
    /layers/heroku_go/shim/go1.21.6/go/src/runtime/panic.go:914 +0x21f
github.com/zeromicro/go-zero/core/stat/internal.isCgroup2UnifiedMode.func1()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/internal/cgroup_linux.go:231 +0x119
sync.(*Once).doSlow(0x0?, 0xc00006bf20?)
    /layers/heroku_go/shim/go1.21.6/go/src/sync/once.go:74 +0xbf
sync.(*Once).Do(...)
    /layers/heroku_go/shim/go1.21.6/go/src/sync/once.go:65
github.com/zeromicro/go-zero/core/stat/internal.isCgroup2UnifiedMode()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/internal/cgroup_linux.go:222 +0x2c
github.com/zeromicro/go-zero/core/stat/internal.currentCgroup()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/internal/cgroup_linux.go:41 +0xf
github.com/zeromicro/go-zero/core/stat/internal.effectiveCpus()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/internal/cpu_linux.go:107 +0x13
github.com/zeromicro/go-zero/core/stat/internal.initialize()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/internal/cpu_linux.go:31 +0x17
sync.(*Once).doSlow(0xc00031e0c0?, 0xc00031e120?)
    /layers/heroku_go/shim/go1.21.6/go/src/sync/once.go:74 +0xbf
sync.(*Once).Do(...)
    /layers/heroku_go/shim/go1.21.6/go/src/sync/once.go:65
github.com/zeromicro/go-zero/core/stat/internal.RefreshCpu()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/internal/cpu_linux.go:61 +0x30
github.com/zeromicro/go-zero/core/stat.init.1.func1.1()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/usage.go:34 +0xf
github.com/zeromicro/go-zero/core/threading.RunSafe(0xc00006bfa0?)
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/threading/routines.go:38 +0x33
github.com/zeromicro/go-zero/core/stat.init.1.func1()
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/usage.go:33 +0x113
created by github.com/zeromicro/go-zero/core/stat.init.1 in goroutine 1
    /layers/heroku_go/shim/go-path/pkg/mod/github.com/zeromicro/go-zero@v1.6.2/core/stat/usage.go:24

To prevent this panic, this contribution adds support for a new go build tag nocgroup which will build core/stat/internal/cpu_other.go instead of core/stat/internal/cpu_linux.go.

Example usage:

go build -tags nocgroup ...

@kevwan kevwan added this pull request to the merge queue Mar 1, 2024
Merged via the queue into zeromicro:master with commit a7363f0 Mar 1, 2024
6 checks passed
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.

None yet

2 participants