Fix the conflict between global sessions & local sessions in socks/socks.go #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix the conflict between global variable sessions in socks/socks.go and local variable sessions in pickConn function of socks/socks.go.
问题
运行时发现会有少数连接无响应问题。使用
--debug
进行跟踪调试发现问题发生在文件socks/socks.go
里,其中函数pickConn
的sessions
是通过传参得到的局部变量,不是真正的全局sessions
池,所以当调用pickConn
并传入全局sessions
后,pickConn
里的sessions
就固定在传入时的样子,同时pickConn
里的无效连接移除不会作用于全局变量sessions
,只会生效于局部变量sessions
。这将使sessions
池中的失效连接并未被实际移除,同时pickConn
中的局部sessions
池不会有新增连接的加入(新增操作只作用于全局sessions
池)导致pickConn
有大概率发生死循环(传入sessions
为空数组或者传入的sessions
里的所有连接都失效时)。长时间运行可能导致更严重的内存泄露。问题表现
--debug
模式中,一直提示No scf server connections
。复现例子
修复
有几种简单的修复方式,
1、
pickConn
传参时改传全局sessions
池的地址2、
pickConn
不传参,函数里直接使用全局sessions
3、其他
为了代码的简洁和易读性这里选择第二种方式。