Large builds and parallel tests open many files and sockets at once. When the open-file ulimit is low, the toolchain hits the cap and fails with "too many open files".
What this error means
A build or test fails with too many open files opening a package file or socket. The runner file-descriptor limit was exceeded under parallelism.
go
open /home/runner/go/pkg/mod/example.com/lib@v1.2.0/file.go: too many open files
Common causes
Low file-descriptor ulimit
The default soft limit is too low for a large parallel build or test run.
Excessive build parallelism
High -p fans out many compile actions, each holding open files, exhausting the limit.
How to fix it
Raise the open-file limit
Increase the soft ulimit before building.
.github/workflows/ci.yml
- run:|ulimit -n 8192go build ./...
Reduce parallelism
Lower -p so fewer files are open at once.
shell
go test -p 2 ./...
How to prevent it
Raise ulimit -n in CI for large builds.
Cap -p when descriptor pressure is high.
Close files and connections promptly in tests.
Frequently asked questions
What causes ""too many open files""?
The default soft limit is too low for a large parallel build or test run.