简体   繁体   English

当有足够的文件句柄可用时,Go程序用尽了文件句柄

[英]Go program running out of file handles when there are plenty file handles available

I have a golang program that connects to other services (and a local consul agent) and when talking to the consul agent it's failing with the following error: 我有一个连接到其他服务(和本地领事代理)的golang程序,当与领事代理交谈时,它失败并显示以下错误:

Put http://localhost:9501/v1/kv/health_checks/item: dial tcp: lookup localhost: too many open files

And this is all good, I can just check how many open files the system and the program has, right? 这一切都很好,我可以检查一下系统和程序有多少个打开的文件,对吗?

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7871
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 16384
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 7871
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

And lsof : lsof

lsof | wc -l
5343

This is still way below the limit. 这仍然远低于限制。 Other programs in the system are all good, I can CURL services, I can CURL this consul agent, create files and everything, but the golang program continues to fail. 系统中的其他程序都很好,我可以使用CURL服务,也可以使用CURL此领事代理,创建文件以及所有内容,但是golang程序仍然失败。

Any ideas on how I could debug this? 关于如何调试此功能的任何想法? Where should I be looking at? 我应该在哪里看?

Any ideas on how I could debug this? 关于如何调试此功能的任何想法? Where should I be looking at? 我应该在哪里看?

Send the program a SIGQUIT while it is running. 在程序运行时向其发送SIGQUIT。 This will make a backtrace of all the running go routines. 这将追溯所有正在运行的go例程。 You'll probably find your culprit in there. 您可能会在其中找到罪魁祸首。

My money would be on forgetting to Close() the Body of an http.Response as that is what I do the most often! 我的钱是因为忘记了Close()http.Response的主体,因为这是我最常做的事情!

如果要连接到不同的端点/服务(即,如果您正在运行搜寻器),请考虑关闭空闲连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM