Skip to content

Mux client: Fix b.UDP being overwritten by the next frame - #6822

Merged
RPRX merged 1 commit into
XTLS:mainfrom
4RH1T3CT0R7:fix/mux-udp-dest-alias
Oct 8, 2026
Merged

RPRX merged 1 commit into
XTLS:mainfrom
4RH1T3CT0R7:fix/mux-udp-dest-alias

Conversation

@4RH1T3CT0R7

Copy link
Copy Markdown
Contributor

#5902 was closed asking where b.UDP gets overwritten after it's assigned. here: ClientWorker.fetchOutput reuses one meta for every frame and handleStatusKeep passes &meta.Target to PacketReader, so all UDP packets of a worker share one Destination and the next Unmarshal rewrites it while earlier packets are still queued. socks, TUN and dokodemo reply from b.UDP, so replies can come from the wrong peer

PacketReader now keeps its own copy of dest. the new test fails on main (earlier replies report the next frame's source) and passes with this, -race is clean. not sure this is what crashed in #5901, that trace is server side

ClientWorker.fetchOutput reuses one FrameMetadata for every frame and
PacketReader put &meta.Target into b.UDP, so all UDP packets of a worker
pointed at the same Destination. Parsing the next frame rewrote the
source of packets still queued downstream.

PacketReader now keeps its own copy of the destination.
@RPRX

RPRX commented Sep 27, 2026

Copy link
Copy Markdown
Member

@Fangliding

@RPRX

RPRX commented Sep 29, 2026

Copy link
Copy Markdown
Member

@Fangliding 搞完 #6866 后看看这个,如果不熟的话我看吧,虽然我忘完了

@Fangliding Fangliding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉以前出过类似的bug

@RPRX

RPRX commented Oct 5, 2026

Copy link
Copy Markdown
Member

感觉有点怪,追踪了下代码,不只是 client 会调用到这里,出问题的调用链是?

@4RH1T3CT0R7

Copy link
Copy Markdown
Contributor Author

only the client keeps one FrameMetadata for the whole connection: fetchOutput declares var meta before its loop and handleStatusKeep passes &meta.Target down to PacketReader, which puts that pointer into b.UDP. the next meta.Unmarshal rewrites Target while the earlier packet is still queued in the session's pipe, so its reader gets the next frame's address

the server makes a new meta in every handleFrame, so it is fine there

patterniha pushed a commit to patterniha/Xray-core that referenced this pull request Oct 8, 2026
Early merge of XTLS#6822 (PR head d19da7e), squashed, ahead of
it landing upstream: XTLS#6822
@RPRX

RPRX commented Oct 8, 2026

Copy link
Copy Markdown
Member

罢了,UDP 性能以后再优化吧

@RPRX
RPRX merged commit 836a6fe into XTLS:main Oct 8, 2026
40 checks passed
@anonymously-hidden

anonymously-hidden commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

@4RH1T3CT0R7
Greetings.
Thanks for your changes, regarding #7097 which was closed due to complexity , I worked out with OpenCode Muse Spark 1.3 , Revalidated , debugged and tried to give it the right direction that fits xray-core architecture and acceptable for maintainers via claude sonnet 5.5; the issue is well described in 7097 , what i achieved was really plausible and i didn't even encounter any in-game errors that i would get regularely , i also ran some local tests and it was ok; if you have time & interested, please take a look at https://github.com/Ahmad-2213/Xray-core/commits/main/ from yesterday , see whether it's possible for you to implement it for original repo?
The direction is towards ACKs that @Fangliding mentioned in the issue, during the fixes, i made several exceptions such as xtls vision compatibility , excluding udp and etc...
Thanks in advance.

@4RH1T3CT0R7

Copy link
Copy Markdown
Contributor Author

@Ahmad-2213 sorry, no. the maintainers turned this down in #7097, so it is not mine to bring in

fanymagnet pushed a commit to fanymagnet/Xray-core that referenced this pull request Oct 8, 2026
Jolymmiles added a commit to Jolymmiles/Xray-core that referenced this pull request Oct 10, 2026
TestClientWorkerUDPSource (upstream XTLS#6822) left its client worker, the
live UDP session and the replies it kept checked out until the test
process exited. A cleanup registered before the assertions now releases
the replies, ends the session input and the carrier, and waits for the
worker to close; reads from the pipes are bounded by 5 s.

Review finding R1-4 on PR #33.
Jolymmiles added a commit to Jolymmiles/Xray-core that referenced this pull request Oct 10, 2026
common/mux/BASELINE.md records BenchmarkServerWorkerKeepAliveFrames
before and after upstream's PacketReader fix (XTLS#6822): the command,
revisions, Go version, host, six samples a side, medians, ranges,
allocation counts, the escape-analysis cause and the limits of the
measurement.

Review finding R1-2 on PR #33.
TaiLerV pushed a commit to TaiLerV/Xray-core-up that referenced this pull request Oct 13, 2026
BenchmarkServerWorkerKeepAliveFrames feeds a ServerWorker a stream of
KeepAlive frames, one frame per op. It records the effect of upstream's
PacketReader fix (XTLS#6822): copying the destination keeps handleFrame's
FrameMetadata on the stack, so the server no longer allocates it for
every frame.

go test -run '^$' -bench BenchmarkServerWorkerKeepAliveFrames -benchmem
-count=6 ./common/mux, Go 1.27.2 linux/amd64, medians:
  before (740205a): 61.0 ns/op, 98 B/op, 3 allocs/op
  after:             53.0 ns/op, 50 B/op, 2 allocs/op
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.

4 participants