Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

Add UserConnTracker to manage user connection cancellations across proxies

Open ImMohammad20000 opened this issue 8 months ago • 48 comments

there is an old bug that lead to a big issue in panels that leve connections open when users remove from inbounds via gRPC api the connection to that user dose not close in some cases so i implement a connection tracker that track all connections and close theme when users remove from the inbounds

an example of the issue is user limited to 1GB but becouse connections not closed it used 18GB

image

ImMohammad20000 avatar Mar 25 '26 15:03 ImMohammad20000

https://github.com/XTLS/Xray-core/issues/5401 连接追踪是会加的,不过怎么设计还要再考虑下

我看了下你的代码,为啥要 register unregister,每个 user 内存中自带一个 ctx 然后被 remove 时直接 cancel() 不就行了

~~应该不用考虑整个入站被移除?那个连端口都被释放了~~

RPRX avatar Mar 26 '26 14:03 RPRX

I considered that approach, but I wanted to ensure connections are tracked across all proxies without relying on each inbound’s internal context, especially since the removal comes via gRPC API and the user might be referenced from multiple places. Using a separate tracker makes it explicit and easier to debug. Happy to refactor if you think a simpler ctx-based approach inside each user struct.

ImMohammad20000 avatar Mar 26 '26 15:03 ImMohammad20000

这不就是个机场计费 helper

Fangliding avatar Mar 26 '26 16:03 Fangliding

~~等新的正式版发布后再讨论一下吧~~

RPRX avatar Mar 27 '26 09:03 RPRX

这不就是个机场计费 helper

Another pr and again you're trying to make people work looks like useless. I wonder when this is going to end...

M03ED avatar Mar 27 '26 22:03 M03ED

这个加了后理论上能按 email 获取到 user 的所有活跃连接吧?~~突然想到 online map~~

RPRX avatar Mar 29 '26 09:03 RPRX

With this added, theoretically, it should be possible to retrieve all active connections for a user by email, right? It suddenly reminded me of online maps.

yes you can do that too by counting the cancel functions

ImMohammad20000 avatar Mar 29 '26 09:03 ImMohammad20000

在我看来 *ray 缺的一个重要功能是连接级相关的 API https://github.com/XTLS/Xray-core/pull/5722#issuecomment-3953811775

*ray 的 GUI 客户端都没有像 Clash/Mihomo 那样有显示哪些连接正在活跃、用了多少流量等 https://github.com/XTLS/Xray-core/issues/5401

仅这个 PR 的话也可以接受,但如果一步到位把上述功能给实现了当然更好,@ImMohammad20000 有兴趣吗

RPRX avatar Mar 29 '26 12:03 RPRX

这不就是个机场计费 helper

Another pr and again you're trying to make people work looks like useless. I wonder when this is going to end...

AI时代代码又不值钱 AI堆垃圾反而负收益 我对这种只是为了售卖节点的功能一直不喜欢 只能说你们一直提交这样的pr

以后真有人来挖掘史山的时候会发现这里有一个看起来很高级的什么 conntrack 模块 结果翻一下调用唯一的作用就是为了在 remove user 的时候触发一个回调

Fangliding avatar Mar 29 '26 12:03 Fangliding

~~只能说“机场后端”的功能需求从 v2ray 时代开始就一直就有吧,只是中国人喜欢弄个闭源机场后端卖钱,外国人还更开源些~~

堵不如疏吧,把一个仅机场能用的功能扩展为对 Xray 自身整体的完善,这个 PR 如果原样合并的话后续肯定也会被替代的

RPRX avatar Mar 29 '26 12:03 RPRX

@RPRX I added a new package for connectiontracker also implemented some new apis ListConnections, CloseConnection, GetUserStats, StreamConnections that help track the connectiones and get information from them

ImMohammad20000 avatar Mar 30 '26 19:03 ImMohammad20000

全是AI写的你自己检查过么。。。

Fangliding avatar Mar 30 '26 19:03 Fangliding

Its not all by ai and yes i checked the code before i push it @Fangliding

ImMohammad20000 avatar Mar 30 '26 19:03 ImMohammad20000

~These changes will definitely cause panics in high-load situations. Is it possible to make such significant changes optional? don't want to risk.~

kastov avatar Mar 30 '26 19:03 kastov

~These changes will definitely cause panics in high-load situations. Is it possible to make such significant changes optional? don't want to risk.~

My goal was a simple tracker that close the open connections And my second commit just added an api to the original disine I dont think this create any big issue in the app

ImMohammad20000 avatar Mar 30 '26 19:03 ImMohammad20000

这些奇奇怪怪的东西一定要全部糊进core里面吗

wyx2685 avatar Mar 30 '26 19:03 wyx2685

Its not all by ai and yes i checked the code before i push it @Fangliding

那你可以解释为什么 WrapConn 根本没地方调用吗 RegisterWithMeta 的第二个返回值根本没任何人使用

Fangliding avatar Mar 30 '26 20:03 Fangliding

Any plan for this? @RPRX

ImMohammad20000 avatar Apr 12 '26 06:04 ImMohammad20000

我个人觉得这个功能是可以有的,但对其他人来说这么多代码目前只实现了这一个功能的话争议过大

Rebase 一下,顺便实现 https://github.com/XTLS/Xray-core/issues/5401 做成一整套系统吧,会合并

RPRX avatar Apr 12 '26 07:04 RPRX

如果 vibe 含量过高,我觉得还是谨慎点好

Meo597 avatar Apr 12 '26 08:04 Meo597