go
system_error
ai_generated
partial
accept tcp [::1]:8080: accept4: 系统中打开的文件过多
accept tcp [::1]:8080: accept4: too many open files in system
ID: go/too-many-files-open-in-docker
80%修复率
82%置信度
1证据数
2024-01-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Go 1.20 | active | — | — | — |
| Go 1.21 | active | — | — | — |
| Go 1.22 | active | — | — | — |
根因分析
系统范围的文件描述符限制或进程限制已被超出,通常由于 Go 服务器中的文件句柄泄漏或高并发导致。
English
The system-wide file descriptor limit or per-process limit has been exceeded, often due to leaked file handles or high concurrency in a Go server.
官方文档
https://go.dev/doc/effective_go#leaks解决方案
-
Increase system-wide file descriptor limit: edit /etc/sysctl.conf with 'fs.file-max = 100000' and apply with sysctl -p.
-
Check for leaked file handles using lsof -p <pid> and ensure all resources (http.Response.Body, os.File) are properly closed in all code paths, using defer for cleanup.
-
Use a connection pool with limits (e.g., http.Transport.MaxIdleConnsPerHost) to prevent excessive file descriptor usage.
无效尝试
常见但无效的做法:
-
90% 失败
Temporary fix; the error will reoccur once file descriptors accumulate again.
-
60% 失败
May not affect system-wide limits; also does not address the root cause of file descriptor leaks.
-
50% 失败
If close() fails silently, file descriptors may still leak.