Skip to content

Instantly share code, notes, and snippets.

@leveryd
Created January 10, 2023 02:59
Show Gist options
  • Save leveryd/2cf4825a11cddde1bfc90d73423d6e1d to your computer and use it in GitHub Desktop.
Save leveryd/2cf4825a11cddde1bfc90d73423d6e1d to your computer and use it in GitHub Desktop.

背景

中间有一段时间没有数据

如果重启proxify pod,es就会又有数据。就像图中那样

为什么会这样?

日志中看到了报错

2023/01/09 15:23:58 [056] INFO: Exiting on EOF

[WRN] Error while logging: error thrown by elasticsearch: dial tcp 10.233.3.77:9200: connect: cannot assign requested address
[WRN] Error while logging: error thrown by elasticsearch: dial tcp 10.233.3.77:9200: connect: cannot assign requested address
[WRN] Error while logging: error thrown by elasticsearch: dial tcp 10.233.3.77:9200: connect: cannot assign requested address

是因为open files 文件句柄数有最大值限制吗?

/ # lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr
  28300 /usr/local/bin/proxify
     10 /bin/busybox
/ # ulimit -n
1048576
/ #

似乎也没有到最大值

那为什么会报这个错呢?

网上文章说原因是 客户端端口号 分配完了

可以看到 10.233.3.77:9200 的链接客户端端口号也只有2w+,并没有到达65535,这能算作是 客户端端口号 分配完了吗?

不过奇怪的是为什么ESTABLISHED状态链接这么多?

/ # netstat -antp | grep 10.233.3.77:9200|grep ESTABLISHED|wc -l
28234

为什么这么多ESTABLISHED?

ESTABLISHED 状态说明客户端和服务端正在传输业务数据

所以,猜测是代码中忘了释放http链接了。后来一看,确实是

projectdiscovery/proxify#215

怎么解决established状态这么多的问题

/ # sysctl -a|grep tcp_fin_timeout
net.ipv4.tcp_fin_timeout = 60
/ # sysctl -w net.ipv4.tcp_fin_timeout=10
sysctl: error setting key 'net.ipv4.tcp_fin_timeout': Read-only file system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment