Skip to content

VLESS Multiplex (mux.cool): Replace MutexWriter with buf.BufferedWriter - #7359

Merged
RPRX merged 3 commits into
mainfrom
mux-write
Nov 10, 2026
Merged

RPRX merged 3 commits into
mainfrom
mux-write

Conversation

@Fangliding

@Fangliding Fangliding commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

两行完工的东西何苦呢(

@RPRX

RPRX commented Nov 9, 2026

Copy link
Copy Markdown
Member

从哪想的这么精准的组件,我都全忘了,看来还是要多看代码

不过 pipe 的 Interrupt 和 Close 似乎有区别,后者不会把内存放回 pool 中?还是说会被 GC?不过即使会的话等 GC 有点慢了

@Medium1992

Copy link
Copy Markdown
Contributor

With BufferedWriter, common.Interrupt(link.Writer) in monitor() falls back to Close(), which calls Flush() and takes the same lock. If a session's write is stuck on the full uplink pipe (client side, connection dropped during upload), monitor() now blocks on that lock and never reaches the pipe. My client test from #7355 still fails on this change: 3 of 3 session goroutines stay blocked, monitor stuck in BufferedWriter.Flush → Lock.

@RPRX

RPRX commented Nov 9, 2026

Copy link
Copy Markdown
Member

既然确实需要 Interrupt 那就 #7355 吧,其实都无所谓,毕竟我已经决定把 Mux 客户端移进 VLESS 出站,这俩之间没 pipe 了

@RPRX RPRX closed this Nov 9, 2026
@Fangliding

Fangliding commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

既然确实需要 Interrupt 那就 #7355 吧,其实都无所谓,毕竟我已经决定把 Mux 客户端移进 VLESS 出站,这俩之间没 pipe 了

这个writer在core里其他地方用了几年了从未见到此类问题 它有问题核心其他地方都会有问题 要当个事办那这也是个得修的BUG 顶多给它实现一个interrupt接口

@Fangliding Fangliding reopened this Nov 9, 2026
@RPRX

RPRX commented Nov 9, 2026

Copy link
Copy Markdown
Member

它有问题核心其他地方都会有问题

只能说 @Medium1992 提了个好问题,core 里实现了 buf.Writer/Reader 的几乎都没往内层传 Interrupt(),pipe 就可能漏内存

不过这 pipe 机制我也打算让它寿终正寝了,也就 XUDP UoT Migration 强依赖它

@Fangliding

Fangliding commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

pipe无关 这个writer如果真的发生block on write的情况的时候close就是会死锁
我之前处理很多泄露 pipe和这个writer实际基本都不存在

@RPRX

RPRX commented Nov 9, 2026

Copy link
Copy Markdown
Member

突然想到 #5143 (comment)

@RPRX

RPRX commented Nov 9, 2026

Copy link
Copy Markdown
Member

pipe无关

严重漏内存的话也就只能是 pipe 了吧,因为 pipe 里面可以设置大缓存,缓存满了卡住 write 且没人管 read 的话就凉了

@Fangliding

Fangliding commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

漏多少没关系 只要会漏就会越堆越高然后炸缸 早晚的
当然前提是会 目前看来不太会(

@RPRX RPRX changed the title Mux write VLESS Multiplex (mux.cool): Replace MutexWriter with buf.BufferedWriter Nov 10, 2026
@RPRX
RPRX merged commit c43ee98 into main Nov 10, 2026
45 of 46 checks passed
@RPRX

RPRX commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

采用这个 PR 吧


想了一下 pipe 的设计逻辑应该是 Close 的话仍能把里面缓存的数据取出来,Interrupt 的话就是直接清空缓存

所以 #7355 (comment) 应该还有一种情况是,write to pipe 没卡住但从应用程序 read 不出来了所以不继续 copy 而是返回了,就没人管 write to pipe 这侧了,此时再叠上 read from pipe 这侧早没了,如果 pipe 里有一些 buf,就没人把内存放回 pool 了

大概就是这样,不确定好不好触发,还是太烧脑了,尽快改架构吧

Medium1992 pushed a commit to Medium1992/xray-proxy-ros that referenced this pull request Nov 11, 2026
Upstream c43ee98e (XTLS/Xray-core#7359) replaces MutexWriter with an
unbuffered buf.BufferedWriter whose Interrupt reaches the pipe, so 0002
no longer applies and the alpha build failed on it. The client-drop and
KeepAlive tests pass on upstream main with the remaining patches. The
published v26.11.9 image keeps 0002; the next stable tag carries the
upstream fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Medium1992 added a commit to Medium1992/Xray-core-fork that referenced this pull request Nov 11, 2026
Upstream c43ee98 (XTLS#7359) replaced MutexWriter with buf.BufferedWriter,
which passes Interrupt and Close itself, so the fork's MutexWriter fix
(08d45a7) and its test go: common/mux/writer.go is upstream's.
patterniha added a commit to patterniha/Xray-core that referenced this pull request Nov 12, 2026
Brings in XTLS/Xray-core up to c456141 (still v26.11.9):
- Build: build list optimization and build-tag clean-up (XTLS#5824)
- Hysteria transport: proper Brutal behavior; bump quic-go to
  v0.63.1-...a10df75c (XTLS#7356)
- Metrics: close HTTP connections when stopping the Instance (XTLS#7361)
- XDNS finalmask: TCP resolver worker (XTLS#7354)
- VLESS mux.cool: maxConcurrency 128 only for XDRIVE (XTLS#7375); replace
  MutexWriter with buf.BufferedWriter (XTLS#7359)

No conflicts: upstream and the fork changed disjoint files; go.mod/go.sum
are taken from upstream unchanged. The fork's core/core.go version
(26.11.12) is kept.
@RPRX
RPRX deleted the mux-write branch November 19, 2026 12:25
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