Repository navigation
Conversation
修改说明(中文)反复新增、拨号和删除 XHTTP outbound 时,每个新建的流配置都会在全局拨号缓存中留下一个条目。即使额外调用 本次修改让节点删除同时关闭 handler 及其拥有的传输资源,包括独立下载配置和所有目标地址的缓存。清理前先将配置标记为已关闭,避免并发获取重新创建缓存;实际关闭操作在管理器锁和缓存锁外执行。 RemoveHandler(tag)
在管理器锁内注销对应 handler
释放管理器锁
+ 关闭该 handler,且只执行一次
+ 关闭其流配置
+ 摘除关联的 XHTTP 缓存
+ 取消请求,关闭当前及已退休的客户端和连接底层 TCP 连接在 TLS/REALITY 封装前登记,保留已有的调用方取消语义。XMUX 在释放选择锁前预留请求计数,普通轮换等待活动请求完成,删除节点则关闭全部关联客户端。迟完成的拨号和关闭后归还的连接不能重新入池。 H1 上传会读取、排空并关闭响应后再归还连接,使请求计数覆盖完整响应过程。多个上传仍可并发;无效响应和 验证结果
每次测量先预热 5 个节点,再执行 200 批、每批最多 5 个节点,共新增 1000 个节点;各场景独立重复两次。修复前后使用相同的 loopback VLESS/XHTTP HTTP/1.1 后端、2 CPU / 2 GiB Linux 容器、Go 1.27.2,并在空闲 10 秒后执行两次 GC。实验还包含直连和仅新增/删除对照。RSS 单独记录,不作为缓存残留或存活 Go 堆的等价指标。 以下检查已通过: go run ./infra/vformat/main.go -mode check -pwd ./
go test ./app/proxyman/outbound ./transport/internet ./transport/internet/splithttp ./core ./app/proxyman/command -count=1 -timeout=180s
go test ./... -run '^$' -count=1 -timeout=120s # 全部包编译检查
go test -race ./transport/internet/splithttp -count=1 -timeout=120s
go test -race ./app/proxyman/outbound -run '^(TestRemoveHandlerCloseMayReplaceTag|TestManagerCloseClearsHandlersBeforeCallbacks|TestHandlerCloseOwnsStreamConfigAndRetainsErrors|TestConcurrentSelectAndHandlerRemoval)$' -count=1 -timeout=90s使用临时 module replacement 指向本次 Core 修改后,libXray 的完整测试也通过。 兼容性与验证边界本次修改可通过代码回退撤销,无需配置或数据迁移;影响范围为网络连接生命周期。 被删除的 handler 和已关闭的流配置不能再次使用,重新注册时需要构造新对象。H1 不再在上一响应完成前通过同一 TCP 连接流水线发送下一请求;公网高延迟环境下的吞吐表现未测量。活动 HTTP/3 请求关闭、挂起的 uTLS/REALITY 握手没有端到端验证;Browser Dialer 浏览器端的请求取消和设备构建也不在本次验证范围内。 |
|
|
|
目前在给 libXray 增加运行时测速功能,这个不解决的话就只能放弃这个 feature 了。 |
|
|
|
来吧,vless-rs ,我早就想搞了。 |
|
我的意思先把 core 底层架构搞清晰些,然后 ctx 多层 with cancel,这样无论是 remove instance/outbound 还是什么的都方便 |
|
|
|
@4RH1T3CT0R7 同样你有空可以 refactor Xray-core 的底层架构让逻辑更清晰些,包括底层传输那里有点绕,尤其是 UDP 部分 至于 /main/distro/main.go 就直接去掉吧,然后话说 app、features 这俩文件夹能不能合并的,core、main 感觉也能简并下 虽然以上基本不是热点代码,主要增强可读性,加上 #6795 (comment) ,完成后送一个 Project X NFT,@Fangliding 你也看看 |
|
能跑就别改了吧 这些都不打紧 |
|
至少架构更清晰些后要实现这个 PR 的目标,以及单连接统计/控制啥的都更简单些, |
Summary
Repeatedly adding, dialing, and removing XHTTP outbounds retains one global dialer-cache entry per fresh stream configuration. Calling
Handler.Close()also leaves those cached clients alive.Close the removed handler and its owned transport state, including independent download settings and every cached destination. Mark configurations closed before cleanup so concurrent acquisition cannot recreate their cache entries. Run cleanup outside manager/cache locks.
Track raw TCP connections before TLS/REALITY wrapping, preserve the existing caller-cancellation semantics, and reserve XMUX usage before releasing the selection lock. H1 uploads consume their responses before returning connections to the pool, so ordinary XMUX retirement waits for outstanding uploads; concurrent uploads remain supported. Invalid responses and
Connection: closeconnections are discarded. Partially successful stream-up dialing closes the already-open download on failure.Evidence
After: 13 focused lifecycle tests cover removal and same-tag replacement outside the manager lock, handler cleanup, config isolation and separate downloads, concurrent acquisition/close, retired active clients, late dialing/pool returns, real TLS H1/H2 cancellation, slow-response H1/H2 rotation, HTTP1 connection-close handling, and partial-dial cleanup.
After: all 240 samples across 16 Linux/arm64 runs have zero retained cache entries; all 12,060 HEAD requests, including warmup, succeed. After idle, each run returns to its baseline FD/goroutine counts with zero socket FDs.
Each measured run adds 1000 nodes in 200 batches of at most 5, after a 5-node warmup; each scenario repeats twice. Measurements use the same loopback VLESS/XHTTP HTTP/1.1 backend, 2 CPU / 2 GiB Linux container, Go 1.27.2, and two GCs after 10 seconds idle. The matrix also includes direct and no-dial controls. RSS is recorded separately and is not treated as retained cache memory.
Passed:
libXray's full test suite also passes with a temporary module replacement pointing to this Core.
go vetstill reports the same eight pre-existing protobufXmuxConfigcopy-lock warnings found in the unmodified baseline.Merge Danger
Door: two-way; code-only revert, without configuration or data migration.
Blast Radius: networking
Removed handlers and stream configurations are terminal: callers must construct new handlers to register them again. H1 no longer pipelines requests on the same connection before the preceding response completes; high-latency WAN throughput was not measured. Active HTTP/3 teardown and stalled uTLS/REALITY handshakes were not exercised end to end. Browser Dialer's browser-side cancellation and device builds are outside this validation.