Skip to content

net: fixes from the second interop round (Vision direct, ML-KEM for Reality, links, DoH h2, pre-auth limits, thread leak) - #3018

Merged
BaseMax merged 21 commits into
mainfrom
fix/vpn-interop2
Nov 9, 2026
Merged

BaseMax merged 21 commits into
mainfrom
fix/vpn-interop2

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 9, 2026

Copy link
Copy Markdown
Member

Second round of checks against real Xray-core 26.11.9, sing-box 1.14.4 and shadowsocks-rust 1.25.0 (checksum-verified, loopback only), covering the features added since round one. The matrix, versions, bug list and rerun steps are in docs/VPN_INTEROP.md.

Bugs found and fixed:

  • Vision: when the inner traffic is TLS 1.3, Xray and sing-box send the direct command and switch to the raw socket; our reader decrypted garbage and every HTTPS session through a Vision server hung. std/tls gets SwitchDirect, the Vision reader honours direct, tunnel.DeadlineDirect carries the switch to the vpn server. A frame ending exactly at a record boundary is now closed on time.
  • Reality with a post-quantum destination: the X25519MLKEM768 share was random bytes, so destinations choosing the hybrid group failed, and Xray drops hellos without it so the firefox and safari profiles never authenticated. Adds SHA-3, SHAKE and ML-KEM-768 to std/tls (checked against Python hashlib and Go crypto/mlkem); the client decapsulates and all profiles except chrome_120 authenticate against Xray.
  • Links: mode=multi / type=multi were dropped (imported clients dialled gun against multi servers); spx and alpn of Reality links stayed percent-encoded.
  • DoH: Quad9's endpoint answers 505 to HTTP/1.1, so the preset resolved nothing; the client retries over HTTP/2 and remembers it.
  • Pre-auth connections: a silent VLESS plain-ws connection was never closed, silent TLS connections each stalled the whole listener for 15 s, a silent trojan-ws connection blocked the listener for good, and there was no per-source limit. Every vpn inbound now goes through transport.Accept; silent connections close at 5 to 10 s; at most 32 connections per address are in handshake (Linux and macOS; no effect on Windows).
  • Address-space leak: handshake, trojan connection, gRPC and Mux reader threads were never joined and each kept an 8 MB stack (3.7 GB after 200 connections). They run detached through tunnel.Go.
  • Double close: a failed inbound handshake closed the stream twice and could close a descriptor already reused by the next client. Closing is idempotent now.

Interop results (byte-exact 1 MiB echo both directions): gRPC gun and multi, Vision over TLS and Reality with inner TLS, Reality with empty flow, ClientHello fragmentation modes, Mux.Cool against Xray, Shadowsocks 2022 UDP and multi-user, Trojan UDP, and the round-one matrix rerun (87/88, the failure is VMess none against Xray 26.x which dropped it). Geo dat reader agrees with an independent Python reader on 15 categories of the real files.

Left: chrome_120 cannot authenticate against Xray 26.x (no hybrid share), outbound streamSettings.fragment in a JSON config is ignored on the client side (works through vpn.Options), handshake deadlines are per read, Mux.Cool over TLS/Reality and VLESS/VMess UDP untested.

Checked with a compiler built from main; new tests have Persian twins and docs cover every new public symbol in en and fa.

… of the data

Xray and sing-box switch to raw TCP after a direct command once the inner
traffic is TLS 1.3, so the reader has to do the same. A frame that ended
exactly at the end of a record was also only closed on the next read, which
never comes after a direct command.
mode=multi on vless and trojan links and type=multi on vmess grpc links were
dropped, so the client dialled gun against a multi server. The reality
parameters (spx, alpn) were taken from the query without percent decoding.
Checked against python hashlib and Go crypto/mlkem: key generation from a
seed, decapsulation of a foreign ciphertext, encapsulation and the implicit
rejection key all agree.
…afari profiles send it

The hybrid share was random bytes, so a Reality destination that picks
X25519MLKEM768 (Google, Cloudflare, anything on OpenSSL 3.5) made the
handshake fail with our client. The client now keeps the ML-KEM seed and
decapsulates the server share. Xray also drops hellos without the hybrid
share, so the firefox and safari profiles never authenticated.
Quad9's DoH endpoint only speaks HTTP/2 and answered every HTTP/1.1 query with
505, so the quad9 preset never resolved anything. The client now retries over
h2 (ALPN h2, GET or POST) and remembers that the server needs it.
… source address

A silent client used to stall the whole listener: the TLS handshake of a vless
inbound and the websocket upgrade of a trojan one ran on the accept thread
(15 s each), and a plain websocket upgrade had no deadline at all. Inbounds now
go through transport.Accept, the trojan upgrade runs in the connection thread,
the accept server deadline drops from 15 to 8 seconds, and each address may
have at most 32 connections in their handshake.
Handshake, trojan connection, grpc reader and mux reader threads were
spawned and never joined, so each kept its 8 MB stack. Every connection of a
vpn server added 16 MB of address space and the server stopped accepting
after a few hundred of them under a 4 GB limit. tunnel.Go starts a detached
thread.
The inbound handshake closes the stream on failure and the accept server
closed it again. The second close hit the descriptor number, which the accept
thread may already have given to a new connection, so a silent client
connected right after a failed one was closed at once.
@BaseMax
BaseMax requested a review from a team as a code owner November 9, 2026 18:39
Copilot AI balanced review requested due to automatic review settings November 9, 2026 18:39
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
salam Ready Ready Preview Nov 10, 2026 1:51am UTC

@BaseMax
BaseMax merged commit 2b93c78 into main Nov 9, 2026
11 of 14 checks passed
@BaseMax
BaseMax deleted the fix/vpn-interop2 branch November 9, 2026 18:39
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown
Contributor
sha=000a51fd782ab75014829eb29727068571fbaac3

🤖 Salam AI review

Verdict: 🛠️ Changes needed before merging

commit 000a51f · 87 files · +3400 −180 · model salam

Summary

This pull request delivers a large second interop round across the VPN, TLS, transport, and link layers, adding ML-KEM/SHA-3 support, Vision direct handling, DoH HTTP/2 fallback, per-source handshake limits, detached worker threads, and idempotent connection closes. The change is broad and appears to follow the documented fixes, but at least one concrete control-flow issue in transport direct switching should be corrected before merge.

What changed

The PR updates many std/net packages and adds tests, interop tooling, and documentation for the second interop round. Notable changes include SwitchDirect support in std/tls and std/net/transport, ML-KEM-768 and SHA-3/SHAKE helpers in std/tls, a real X25519MLKEM768 key share in std/net/utls, HTTP/2 fallback in std/net/doh, per-source handshake limiting in std/net/tunnel, std/net/transport, and std/net/trojan, detached threads through std/net/tunnel/spawn.salam, and idempotent Conn.Close.

Review

  • std/net/transport/conn.salam: SwitchDirect handles KindStream by calling c.up.SetDeadline(tunnel.DeadlineDirect), while _StreamAdapter.SetDeadline translates DeadlineDirect back into SwitchDirect(this.c). That path looks like unbounded recursion; for a plain stream connection direct reading is already raw, so this branch should simply return true (or set a direct flag) instead of re-entering SwitchDirect.
  • std/net/internal/rawsock/rawsock.salam: PeerHost formats an IPv6 peer as 32 hexadecimal digits without colons. This is internally consistent as a map key, but if the value is ever displayed or compared with canonical IPv6 text it will not match.
  • std/net/trojan/server.salam: the handshake path now sets a read deadline only for WebSocket connections. TLS and plain TCP handshakes rely on the TLS record timeout and detached execution; confirm that a silent TLS or plain TCP peer cannot still occupy a worker indefinitely.
  • std/net/vpn/run.salam: TransportAcceptor.Accept now always uses transport.Accept, even where AcceptRaw was previously used. This is likely intended, but it changes which connections perform transport-level upgrading and source accounting, so callers and tests relying on the old raw path should be checked.
  • std/net/tunnel/spawn.salam: the Windows branch uses _beginthread with a zero stack size. Confirm that this selects the platform default stack rather than an unusably small one.

Tests

The PR adds English and Persian tests for DoH HTTP/2, ML-KEM, transport double close, gRPC link mode, source limits, and Vision direct. I did not execute the compiler or tests, so I cannot confirm that all new and modified tests pass; the review is based on the supplied diff.

Risks

The main risk is the apparent recursion in transport.SwitchDirect for stream connections, which could hang a Vision reader if that path is exercised. The remaining items are compatibility and platform-specific questions rather than confirmed defects. If the diff was truncated, parts of std/net/trojan/server.salam and the interop tooling were not fully visible.


⚠️ This review was written automatically by an AI and may contain mistakes. It is a helper for maintainers, not a replacement for a human review: check the code yourself before merging.

This branch was successfully deployed

1 active deployment
Preview — 000a51fd Deployed Nov 10, 2026 by vercel[bot]
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.

2 participants