Skip to content
Latchkey

Go "too many open files" (ulimit) - Fix in CI

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

  1. Increase the soft ulimit before building.
.github/workflows/ci.yml
- run: |
    ulimit -n 8192
    go build ./...

Reduce parallelism

  1. 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.
How do I fix "too many open files"?
Raise the open-file limit

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card