Skip to content

Track alive hy conn - #7102

Closed
Fangliding wants to merge 1 commit into
mainfrom
hy-timeout
Closed

Fangliding wants to merge 1 commit into
mainfrom
hy-timeout

Conversation

@Fangliding

Copy link
Copy Markdown
Member

可能是 #7100 的一个解决方法 解决一下quic没有应用层超时的问题(感觉遇到过好几次了)
cc: @LjhAUMEM

@lie-must-die

Copy link
Copy Markdown

Thanks, this fixes the leak I reported in #7100. I tested a similar approach locally
(N core restarts with keepAlivePeriod set: 5 leaked QUIC conns before, 0 after the
idle window).

Two small notes, in case they're useful:

  1. Pool entries are still never removed from manager.m, so each instance restart
    leaves an empty client (TLS config etc.) in the map for the process lifetime.
    Deleting clients with StatusNull in clientManager.clean would need to guard
    against a concurrent Dial that already looked the client up (e.g. a refcount
    taken under the manager lock).
  2. I have a test (dialer_test.go) covering open TCP stream / UDP session keeping
    the conn alive past the idle timeout, idle close, and concurrent dial/close under
    -race. Happy to push it on top of this PR if you want it.

@LjhAUMEM

LjhAUMEM commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

没有活跃 tcp udp 主动关掉 keepalive quic 改变的行为太大了,原始诉求应该是 core instance 关掉所有连接也要关掉

看了下 ray 里是这样关闭出站

common.Close(h.proxy)

但是 process 拿到的又不是原始 quic,现在初步想的是 ctx 多传个 close 后自增 id,id 不同在 dial 里先清理掉之前的,transport 就继续保持唯一 manager

但除非在 process 里记录下所有 conn 不然直接进 buf copy 上面的 common.Close 也会没用,我记得我还标了

// Sadly, closing the core does not first close the sockets created for outbound connections

说到多实例还想到这个 #6483 (comment)

@LjhAUMEM

LjhAUMEM commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

如果只是针对 hy 还有个优雅的办法是给注册的全局 dialer 加个 common close 跟随着 instance close

func init() {
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}

@Fangliding

Fangliding commented Oct 8, 2026 •

Copy link
Copy Markdown
Member Author

没有活跃 tcp udp 主动关掉 keepalive quic 改变的行为太大了,原始诉求应该是 core instance 关掉所有连接也要关掉

看了下 ray 里是这样关闭出站

common.Close(h.proxy)

出站是实例 传输 不是 它只是注册一个函数 由于屎山代码的缘故它的生命周期跟包挂钩了 这种情况其他传输都能被自带的应用层超时关闭 但是 quic-go 的设计非常蛋疼 如果 keepalive 必须主动释放关闭 这里只是补上了应用层超时这个行为
如果让 dialer 跟 instance 关其他传输也要改

而且这里并不是快速主动关闭 它需要完全无存活的tcp/udp后再过300秒超时时间才驱逐连接 由于quic的全复用机制理论上使用期间几乎不会达到

@LjhAUMEM

LjhAUMEM commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

那自增 id 方案呢,不会有 300s,存活周期取决于 instance close 后到 new instance dial 之间,就是这样客户端也必须保持 one instance 了

@Fangliding

Copy link
Copy Markdown
Member Author

那自增 id 方案呢,不会有 300s,存活周期取决于 instance close 后到 new instance dial 之间,就是这样客户端也必须保持 one instance 了

感觉不需要自增id 我去看了一下ctx里是可以提取到instance的 用一个变量持有instance 获得新 dial 的时候看一下是否一致不是就清理掉 然后在 WeakCacheMap 放旧的instance避免老的顶掉新的
但是这么有个问题是close后新dial才能驱逐 单纯close不会停 使用者如果换一个非hy的节点就感知不到了

@LjhAUMEM

LjhAUMEM commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

忘记可以拿到 Instance 了,那这样新老也不用判断了,给 Instance 实现个 IsClosed,client 的 status 多看一下这个返回 StatusInactive 应该就可以

@Fangliding Fangliding closed this Oct 8, 2026
@LjhAUMEM

LjhAUMEM commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

怎么关闭了,那晚上我开一个吧

@Fangliding

Copy link
Copy Markdown
Member Author

因为分支叫 hy-timeout 直接改的话名字不对

RPRX pushed a commit that referenced this pull request Oct 10, 2026
@RPRX
RPRX deleted the hy-timeout branch November 21, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants