Skip to content

Add UserConnTracker to manage user connection cancellations across proxies#5844

Open
ImMohammad20000 wants to merge 4 commits intoXTLS:mainfrom
ImMohammad20000:UserConnTracker
Open

Add UserConnTracker to manage user connection cancellations across proxies#5844
ImMohammad20000 wants to merge 4 commits intoXTLS:mainfrom
ImMohammad20000:UserConnTracker

Conversation

@ImMohammad20000
Copy link
Copy Markdown

@ImMohammad20000 ImMohammad20000 commented Mar 25, 2026

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

@RPRX
Copy link
Copy Markdown
Member

RPRX commented Mar 26, 2026

#5401 连接追踪是会加的,不过怎么设计还要再考虑下

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

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

@ImMohammad20000
Copy link
Copy Markdown
Author

ImMohammad20000 commented Mar 26, 2026

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.

@Fangliding
Copy link
Copy Markdown
Member

这不就是个机场计费 helper

@RPRX
Copy link
Copy Markdown
Member

RPRX commented Mar 27, 2026

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

@M03ED
Copy link
Copy Markdown
Contributor

M03ED commented Mar 27, 2026

这不就是个机场计费 helper

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

@RPRX
Copy link
Copy Markdown
Member

RPRX commented Mar 29, 2026

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

@ImMohammad20000
Copy link
Copy Markdown
Author

ImMohammad20000 commented Mar 29, 2026

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

@RPRX
Copy link
Copy Markdown
Member

RPRX commented Mar 29, 2026

在我看来 *ray 缺的一个重要功能是连接级相关的 API #5722 (comment)

*ray 的 GUI 客户端都没有像 Clash/Mihomo 那样有显示哪些连接正在活跃、用了多少流量等 #5401

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

@Fangliding
Copy link
Copy Markdown
Member

这不就是个机场计费 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 的时候触发一个回调

@RPRX
Copy link
Copy Markdown
Member

RPRX commented Mar 29, 2026

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

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

…n management

- Add protobuf definitions for connection tracking commands including ListConnections, CloseConnection, GetUserStats, and StreamConnections.
- Generate gRPC client and server code from the protobuf definitions.
- Implement a connection tracker that maintains active connections, allows forced disconnections, and provides real-time statistics.
- Create API commands for listing connections, closing connections, streaming connection events, and retrieving user statistics.
- Add tests for connection tracking functionality to ensure correctness and thread safety.
@ImMohammad20000
Copy link
Copy Markdown
Author

@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

@Fangliding
Copy link
Copy Markdown
Member

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

@ImMohammad20000
Copy link
Copy Markdown
Author

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

@kastov
Copy link
Copy Markdown
Contributor

kastov commented Mar 30, 2026

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

@ImMohammad20000
Copy link
Copy Markdown
Author

ImMohammad20000 commented Mar 30, 2026

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

@wyx2685
Copy link
Copy Markdown
Contributor

wyx2685 commented Mar 30, 2026

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

@Fangliding
Copy link
Copy Markdown
Member

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

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

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.

6 participants