Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 签名服务器的TCP链接没有正确结束导致系统缓冲区空间不足或队列已满 #2368

Closed
4 tasks done
BlackcatWatcher opened this issue Aug 11, 2023 · 10 comments
Labels
bug? The issue author think this is a bug

Comments

@BlackcatWatcher
Copy link

BlackcatWatcher commented Aug 11, 2023

请确保您已阅读以上注意事项,并勾选下方的确认框。

  • 我已经仔细阅读上述教程和 "提问前需知"
  • 我已经使用 dev分支版本 测试过,问题依旧存在。
  • 我已经在 Issue Tracker 中找过我要提出的问题,没有找到相同问题的ISSUE。
  • 我已知晓并同意,此处仅用于汇报程序中存在的问题。若这个 Issue 是关于其他非程序本身问题,则我的 Issue 可能会被无条件自动关闭或/并锁定。(这些问题应当在 Discussion 板块提出。)

go-cqhttp 版本

94a3ff5

运行环境

Windows (64)

运行架构

x86

连接方式

WebSocket (反向)

使用协议

6 | aPad

重现步骤

BUG说明:
在使用一段时间后出现系统缓冲区空间不足或队列已满,导致无法正常服务。
(其他出现问题的人也可以临时使用注册表在HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters新增MaxUserPort,Dword格式,不设置时默认5000,你可以设置为十进制65543)

在cmd使用以下指令查看建立的链接数:
netstat -n | find /C /I "established"
结果显示占用了2万多个TCP端口,都是由192.168.1.5(本机)连接向127.0.0.1:8080(签名服务器)的。

看了Fix: SignServer TCP ping for custom port #2353貌似修的不是这个BUG。

重现步骤:
1、使用windows版本的qsign1.1.7,在本机环境搭建签名服务器。
2、Windows环境(cmd控制台)下运行gocq(94a3ff5)连接上签名服务器。
3、机器人正常收发消息使用,占用的端口数会逐渐增加。

期望的结果是什么?

不知道是qsign还是gocq的问题,总之报告下

实际的结果是什么?

正确处理TCP连接

简单的复现代码/链接(可选)

No response

日志记录(可选)

[2023-08-11 00:04:23] [WARNING]: 警告:  123456 图片上传失败: upload failed: dial tcp 157.148.55.114:14000: bind: 由于系统缓冲区空间不足或队列已满不能执行套接字上的操作。 
[2023-08-11 00:04:23] [WARNING]: 群消息发送失败: 消息为空. 
[2023-08-11 00:04:40] [WARNING]: 获取sso sign时出现错误: Post "http:https://127.0.0.1:8080/sign": dial tcp 127.0.0.1:8080: bind: 由于系统缓冲区空间不足或队列已满不能执行套接字上的操作server: http://127.0.0.1:8080 
[2023-08-11 00:04:40] [WARNING]: token 已过期, 总丢失 token 次数为 3 
[2023-08-11 00:04:40] [WARNING]: 刷新 token 出现错误: Get "http:https://127.0.0.1:8080/request_token?uin=123456": dial tcp 127.0.0.1:8080: bind: 由于系统缓冲区空间不足或队列已满不能执行套接字上的操作server: http://127.0.0.1:8080

补充说明(可选)

No response

@BlackcatWatcher BlackcatWatcher added the bug? The issue author think this is a bug label Aug 11, 2023
@KomeiDiSanXian
Copy link
Contributor

[2023-08-12 16:51:19] [WARNING]: 刷新 token 出现错误: Get "http:https://127.0.0.1:2333
/request_token?uin=3567284738": dial tcp 127.0.0.1:2333: bind: An operation on a
 socket could not be performed because the system lacked sufficient buffer space
 or because a queue was full. server: http:https://127.0.0.1:2333
[2023-08-12 16:51:19] [WARNING]: 获取sso sign时出现错误: Post "http:https://127.0.0.1:
2333/sign": dial tcp 127.0.0.1:2333: bind: An operation on a socket could not be
 performed because the system lacked sufficient buffer space or because a queue
was full. server: http:https://127.0.0.1:2333

补充说明,可能是没有关闭链接?
使用netstat -a发现大量tcp连接建立且没有关闭

1umine added a commit to 1umine/go-cqhttp that referenced this issue Aug 12, 2023
增加对 client 的利用,避免创建过多 clients
@1umine
Copy link
Contributor

1umine commented Aug 12, 2023

可能是WithTimeout每次都新建了一个client导致的(?),试试这个 https://github.com/1umine/go-cqhttp/actions/runs/5841440190 还会不会有这个问题
测试了下没有再出现大量 ESTABLISHED 了,只有一些 TIME_WAIT 的连接,过一会就自动关闭了,数量保持在10个左右。

KomeiDiSanXian added a commit to KomeiDiSanXian/go-cqhttp that referenced this issue Aug 12, 2023
@KomeiDiSanXian
Copy link
Contributor

目前测试下来(*http.Client).CloseIdleConnections() 应该有用,应该就是连接没关

KomeiDiSanXian added a commit to KomeiDiSanXian/go-cqhttp that referenced this issue Aug 12, 2023
@KomeiDiSanXian
Copy link
Contributor

可能是WithTimeout每次都新建了一个client导致的(?),试试这个 https://github.com/1umine/go-cqhttp/actions/runs/5841440190 还会不会有这个问题 测试了下没有再出现大量 ESTABLISHED 了,只有一些 TIME_WAIT 的连接,过一会就自动关闭了,数量保持在10个左右。

我的方案似乎不行,你看看你运行一段时间会不会导致qsign那边jvm空指针报错(

@1umine
Copy link
Contributor

1umine commented Aug 13, 2023

可能是WithTimeout每次都新建了一个client导致的(?),试试这个 https://github.com/1umine/go-cqhttp/actions/runs/5841440190 还会不会有这个问题 测试了下没有再出现大量 ESTABLISHED 了,只有一些 TIME_WAIT 的连接,过一会就自动关闭了,数量保持在10个左右。

我的方案似乎不行,你看看你运行一段时间会不会导致qsign那边jvm空指针报错(

可能是频繁关闭连接创建连接导致的吧。

我运行了一上午,没出问题,netstat 结果和有 WithTimeout 之前的表现是一致的。

@KomeiDiSanXian
Copy link
Contributor

可能是WithTimeout每次都新建了一个client导致的(?),试试这个 https://github.com/1umine/go-cqhttp/actions/runs/5841440190 还会不会有这个问题 测试了下没有再出现大量 ESTABLISHED 了,只有一些 TIME_WAIT 的连接,过一会就自动关闭了,数量保持在10个左右。

我的方案似乎不行,你看看你运行一段时间会不会导致qsign那边jvm空指针报错(

可能是频繁关闭连接创建连接导致的吧。

我运行了一上午,没出问题。

没办法了,先去qsign那边提交个issue看是啥问题,我自己看不出来了

@1umine
Copy link
Contributor

1umine commented Aug 13, 2023

我的方案似乎不行,你看看你运行一段时间会不会导致qsign那边jvm空指针报错(

可能是频繁关闭连接创建连接导致的吧。
我运行了一上午,没出问题。

没办法了,先去qsign那边提交个issue看是啥问题,我自己看不出来了

可能是qsign会复用已有的连接,然后这边请求完之后空闲连接立刻就被关闭了,qsign还留着连接以为没关想继续用,然后导致了异常。

@KomeiDiSanXian
Copy link
Contributor

我的方案似乎不行,你看看你运行一段时间会不会导致qsign那边jvm空指针报错(

可能是频繁关闭连接创建连接导致的吧。
我运行了一上午,没出问题。

没办法了,先去qsign那边提交个issue看是啥问题,我自己看不出来了

可能是qsign会复用已有的连接,然后这边请求完之后空闲连接立刻就被关闭了,qsign还留着连接以为没关想继续用,然后导致了异常。

换dev版本测了一个下午..好像不是我代码的问题(
用最新提交的qsign好像就会崩

@1umine
Copy link
Contributor

1umine commented Aug 14, 2023

可能是qsign会复用已有的连接,然后这边请求完之后空闲连接立刻就被关闭了,qsign还留着连接以为没关想继续用,然后导致了异常。

换dev版本测了一个下午..好像不是我代码的问题(
用最新提交的qsign好像就会崩

好像确实是 qsign 的问题,9h 后崩了,似乎是在 unidbg 这块出了问题,与网络关系不是很大

8月 14, 2023 5:02:42 下午 com.github.unidbg.arm.AbstractARM64Emulator hook
警告: Read memory failed: address=0x561ddf1b, size=4, value=0x0

@KomeiDiSanXian
Copy link
Contributor

可能是qsign会复用已有的连接,然后这边请求完之后空闲连接立刻就被关闭了,qsign还留着连接以为没关想继续用,然后导致了异常。

换dev版本测了一个下午..好像不是我代码的问题(
用最新提交的qsign好像就会崩

大概多久会崩?我用 qsign action 里最新的试了下,目前 5h 了,没出问题。

好像还真是 qsign 的问题,9h 后崩了,似乎是在 unidbg 这块出了问题,与网络关系不是很大

8月 14, 2023 5:02:42 下午 com.github.unidbg.arm.AbstractARM64Emulator hook
警告: Read memory failed: address=0x561ddf1b, size=4, value=0x0

我自己测下来很随机,有时十分钟,有时几个小时

fumiama pushed a commit that referenced this issue Aug 27, 2023
* fix: skip callback error

* update: update comment

* change the logic of callback and auto-register

* add token update prompt.

* fix log buffer string

* fix #2368

增加对 client 的利用,避免创建过多 clients

* refactor: wrap sign request

* feat: impl additional sign servers configuration

* fix error in using configurations.

* fix lint error

* 支持切换回主签名服务器

* feat: support different key and auth

* optimize: find avaliable sign-server

* fix: register instance after server is changed

* fix lint error

* update: add config 'sync-check-servers'

* update: first check master sign-server, or wait 3s

* add checking log & optimize wait for checking done

* fix wrong judge

* add config: rule for changing sign server

* optimize registration logic after changing server

* add some log

* fix #2390

* resolve requested changes in #2389

* update dependency

* fix lint error 'idx is unused'

* refactor: extract sync check and async check logic

* delete async check sign-server
@fumiama fumiama closed this as completed in da9f03f Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug? The issue author think this is a bug
Projects
None yet
Development

No branches or pull requests

3 participants