Fix the conflict between global sessions & local sessions in socks/socks.go#42
Merged
shimmeris merged 1 commit intoshimmeris:mainfrom Mar 10, 2023
Conversation
…nd local variable session in pickConn function of socks/socks.go. Signed-off-by: lanxuage <zx1456817554@gmail.com>
Owner
|
感谢 |
power12317
pushed a commit
to power12317/SCFProxy
that referenced
this pull request
Jan 15, 2026
…d_local_var_conflict Fix the conflict between global sessions & local sessions in socks/socks.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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不传参,函数里直接使用全局sessions3、其他
为了代码的简洁和易读性这里选择第二种方式。