Skip to content

XTLS Vision: Serialize VisionWriter writes from concurrent mux sessions - #7337

Merged
RPRX merged 4 commits into
XTLS:mainfrom
StarProxima:vision-mux-concurrent-writes
Nov 6, 2026
Merged

RPRX merged 4 commits into
XTLS:mainfrom
StarProxima:vision-mux-concurrent-writes

Conversation

@StarProxima

Copy link
Copy Markdown
Contributor

Fixes #7336

Since 4064f8d the VLESS inbound hands its VisionWriter to mux.Server.DispatchLink without a pipe. mux.ServerWorker writes from one goroutine per session, so VisionWriter.WriteMultiBuffer runs concurrently. The padding state (writeOnceUserUUID, IsPadding, NumberOfPacketToFilter) changes outside any lock, while the BufferedWriter lock underneath only covers the socket write. Blocks then reach the wire in a different order from the one their padding was computed in. The client VisionReader passes padding through as data, and the client mux fails with unknown status: <random>, dropping every session on the connection. Details, configs and logs are in the issue.

This PR makes VisionWriter.WriteMultiBuffer hold its own mutex for the whole call, so the padding state and the wire order change together. Mux writes were already serialized by the BufferedWriter lock, so throughput stays the same. On plain TCP Vision only one goroutine writes, so the lock is never contended. The same change covers the VLESS reverse portal with Vision, where mux.ClientWorker writes from one goroutine per session.

TestVisionWriterConcurrentWrites writes to one VisionWriter from two goroutines while the underlying writer holds the first write until the second one lands. Without the lock the second block goes out first without the user UUID, and a VisionReader on the other side returns padding bytes as payload. The test is deterministic: it fails on main without the change and passes with it, with -race as well.

The repro from the issue (100 UDP associations at once through Vision + XUDP):

replies of 100 server data races (-race)
v26.10.31 88, 60, 79 17
this PR 100, 100, 99 0

go test -race ./proxy/ ./common/mux/... ./proxy/vless/... passes.

@RPRX

RPRX commented Nov 6, 2026

Copy link
Copy Markdown
Member

@Fangliding 看你有 commit,能合了吗

@RPRX

RPRX commented Nov 6, 2026

Copy link
Copy Markdown
Member

我看了下,可以先作为修复合并,不过 core 里不该有 concurrent write or read 这种东西,仍需修复深层起因(可能就是这种东西导致了 #5845 ,你试着修下),另外虽然你这么改能 work,但我记得 Golang 的锁是不保证先到先得的,标题我懒得改了

@StarProxima

Copy link
Copy Markdown
Contributor Author

found it. since #5076 the vless inbound gives the mux its conn writer directly and the mux writes from a goroutine per session, before that a pipe sat in between. put the pipe back inside the mux, one per connection, so the VisionWriter mutex isn't needed anymore #7345

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.

XTLS Vision + Mux/XUDP: concurrent mux sessions corrupt the downlink ("common/mux: unknown status")

3 participants