Skip to content

XMC finalmask: Prevent deadlock during bidirectional startup padding - #7430

Merged
RPRX merged 1 commit into
XTLS:mainfrom
TurboRigby:codex/fix-xmc-padding-deadlock
Nov 17, 2026
Merged

RPRX merged 1 commit into
XTLS:mainfrom
TurboRigby:codex/fix-xmc-padding-deadlock

Conversation

@TurboRigby

Copy link
Copy Markdown
Contributor

XMC startup padding can deadlock after #7402 when both directions exceed the connection buffers. Both endpoints write their entire local schedule before starting the packet reader, so neither drains the peer's padding and both writes eventually time out.

Drain incoming xmc:pad packets while sending startup padding. Retain the first non-padding packet and then hand reading back to the packet stream, buffering at most one packet. The padding wire format and configured pauses are preserved. A startup write failure closes the connection to release the pending reader.

For example, this valid schedule can stall both endpoints:

"paddings": [
  {"direction": "c2s", "length": "8388608"},
  {"direction": "s2c", "length": "8388608"}
]

The regression test exercises the full encrypted handshake over net.Pipe with 64 KiB turns and TCP with 8 MiB turns and constrained socket buffers, followed by proxy data in both directions. The pipe handshake failed on both endpoints before the fix. Reader tests cover preserving following packets, read errors, empty reads, and connection closure.

Checked the 57 currently open PRs: only #7423 and #7416 modify XMC. #7423 handles schedule bounds/cancellation and #7416 handles authentication; neither adds concurrent padding reads.

Validation passed:

go test -p=1 ./transport/internet/finalmask/... ./infra/conf -count=1
go test -p=1 -race ./transport/internet/finalmask/xmc -count=1
go run -p=1 ./infra/vformat -pwd . -mode check

@spr334-a

Copy link
Copy Markdown
Contributor

绷不住了

@yandujun363

Copy link
Copy Markdown
Contributor

确实难绷,我这边等下吧。
这玩意BUG太多了,总不能是被麻将传染了吧

@spr334-a

Copy link
Copy Markdown
Contributor

确实难绷,我这边等下吧。

这玩意BUG太多了,总不能是被麻将传染了吧

还有那个部分padding被之前#7402加入的压缩压没的问题,又得等#7423

@yandujun363

Copy link
Copy Markdown
Contributor

还有那个部分padding被之前#7402加入的压缩压没的问题,又得等#7423

这个怪我,我没仔细查

@yandujun363

Copy link
Copy Markdown
Contributor

我可不希望等会出现 PR A 等PR B
然后PR B又等PR A

@RPRX

RPRX commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

不确定会不会有这么大的 padding(?)不过这个,比如说是 c2s 然后 s2c,服务端的逻辑不应该是先读再写吗,为啥先写了?

@RPRX RPRX changed the title XMC: prevent deadlock during bidirectional startup padding XMC finalmask: Prevent deadlock during bidirectional startup padding Nov 17, 2026
@RPRX
RPRX merged commit 82b5b76 into XTLS:main Nov 17, 2026
24 checks passed
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