shirou / gopsutil

psutil for golang
Other
10.28k stars 1.56k forks source link

runtime: program exceeds 10000-thread limit #1644

Open RunningFaster opened 2 months ago

RunningFaster commented 2 months ago

Describe the bug

runtime: program exceeds 10000-thread limit

When I use the toolkit to get disk usage, I get an error at the top.

To Reproduce

"github.com/shirou/gopsutil/disk"

parts, error := disk.Partitions(true)
    if error == nil {
        for _, v := range parts {
            diskInfo, _ := disk.Usage(v.Mountpoint)  // Error
            if diskInfo == nil {
                continue
            }
        }
    }

Expected behavior [A clear and concise description of what you expected to happen.]

Environment (please complete the following information):

Additional context [Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/gopath/pkg/mod"
GONOPROXY="git.mycompany.com,github.com/my/private"
GONOSUMDB="git.mycompany.com,github.com/my/private"
GOOS="linux"
GOPATH="/home/gopath"
GOPRIVATE="git.mycompany.com,github.com/my/private"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.7"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
shirou commented 2 months ago

disk.Usage() does not use goroutine, neither disk.Partitions() on Linux. It is therefore curious that such an error should occur. One possible reason is that your system have more than 10000 partitions. disk.Usage() includes all file system such as squashfs which snap uses. Therefore, it may possibly exceed 10000.

davidnewhall commented 1 day ago

Providing the length of parts, how far into that slice it gets before bombing out, and which partition caused the overload might be helpful.