Repository navigation
Mux client: Fix b.UDP being overwritten by the next frame - #6822
Conversation
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.
|
@Fangliding 搞完 #6866 后看看这个, |
|
感觉有点怪,追踪了下代码,不只是 client 会调用到这里,出问题的调用链是? |
|
only the client keeps one FrameMetadata for the whole connection: fetchOutput declares the server makes a new meta in every handleFrame, so it is fine there |
|
|
|
@4RH1T3CT0R7 |
|
@Ahmad-2213 sorry, no. the maintainers turned this down in #7097, so it is not mine to bring in |
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.
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.
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
#5902 was closed asking where b.UDP gets overwritten after it's assigned. here: ClientWorker.fetchOutput reuses one
metafor every frame and handleStatusKeep passes&meta.Targetto 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 peerPacketReader 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