go
system_error
ai_generated
partial
dial tcp: socket: too many open files
ID: go/too-many-open-files
82%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
File descriptor limit reached. Common in HTTP clients without closing response bodies.
genericWorkarounds
-
95% success Close HTTP response bodies: defer resp.Body.Close()
resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() -
90% success Close file handles, database connections, and other resources with defer
// Always close with defer: f, err := os.Open("file.txt") if err != nil { return err } defer f.Close() // Same for DB connections: rows, err := db.Query(query) if err != nil { return err } defer rows.Close() -
75% success Increase ulimit as a temporary measure: ulimit -n 65536
ulimit -n 65536
Sources: https://pkg.go.dev/os#File
Dead Ends
Common approaches that don't work:
-
Increase ulimit to a very large value
60% fail
Just delays the problem — file descriptors are still leaking
-
Restart the process when limit is hit
80% fail
Hack that doesn't fix the leak
Error Chain
Frequently confused with: