Skip to content

test: expand coverage (graceful shutdown, pure fns, SOCKS5 TCP) + client auto-reconnect#28

Merged
Itsusinn merged 2 commits into
mainfrom
test/coverage-graceful-shutdown-reconnect
Jun 15, 2026
Merged

test: expand coverage (graceful shutdown, pure fns, SOCKS5 TCP) + client auto-reconnect#28
Itsusinn merged 2 commits into
mainfrom
test/coverage-graceful-shutdown-reconnect

Conversation

@Itsusinn

@Itsusinn Itsusinn commented Jun 15, 2026

Copy link
Copy Markdown
Member

Overview

Expands test coverage across the workspace and adds a new configurable client auto-reconnect feature for the TUIC outbound (with tests). No production behavior changes other than the reconnect feature, which is on by default and backward-compatible.

What changed

Graceful shutdown

  • Unit tests for the backend-agnostic server core: the acceptor_loop cancellation primitive (cancel mid-accept, pre-cancelled, benign close, timed-out, fatal error) plus is_tuic_prefix / read_prefix.
  • Integration tests that the cancellation chain drains rather than hangs:
    • TUIC inbound listen loop + per-connection tasks drain on cancel (idle and with a live connection).
    • SOCKS5 inbound accept loop + in-flight session abort on cancel.
    • tuic-client TCP/UDP forwarders drain on cancel.

Pure-function coverage (filling gaps)

  • wind-core: is_private_ip, StackPrefer::from_str, pick_addr_by_preference, filter_addrs_by_preference.
  • wind-socks: parse_udp_request_sync (all ATYPs + malformed headers), unmap_v4_mapped, target_addr_to_socket, convert_addr/convert_to_socks_addr round-trips.
  • wind-base (previously zero tests): resolve_target — IP-literal bypass and domain-via-resolver.

SOCKS5 TCP end-to-end

Dependency-free hand-rolled SOCKS5 client: no-auth and RFC 1929 password auth (correct/incorrect), IPv4 and domain CONNECT with echo round-trip, and the unsupported-command path.

Client auto-reconnect (new feature)

  • TuicOutbound now stores its connection in an ArcSwap. A supervisor task runs one session (heartbeat + incoming handling) until the connection drops, then reconnects with exponential backoff and swaps the fresh connection in — handle_tcp/handle_udp transparently use the new connection. Connection loss is detected promptly via conn.closed().
  • Shutdown is honored even mid-handshake (reconnect races the shutdown token).
  • In-flight streams on the old connection are not resurrected; callers retry and get new streams (correct tunnel-reconnect semantics).
  • Configurable via ReconnectConfig { enabled, initial_backoff, max_backoff }, wired from the client Relay config (reconnect, reconnect_initial_backoff, reconnect_max_backoff) with serde defaults — existing configs keep working unchanged.
  • Tests: pure next_backoff, reconnect-after-server-restart, shutdown-while-reconnecting, reconnect-disabled, and config parsing/defaults.

Reviewer notes

  • The quiche outbound is a builder stub (no live client path), so reconnect targets only the quinn client backend.
  • Relay uses #[serde(default)] with per-field educe defaults, so the three new fields are backward-compatible; one Relay literal in tuic-tests that didn't use ..Default::default() was updated.
  • Verified locally: full cargo build --workspace, cargo +nightly fmt --check, and cargo clippy --tests are clean (no new warnings). Test suites green, including the tuic-tests end-to-end integration suite (full client+server) and 5× stable reruns of the timing-sensitive reconnect test.

🤖 Generated with Claude Code

Itsusinn and others added 2 commits June 15, 2026 21:29
Adds graceful-shutdown coverage across the cancellation chain, fills
pure-function test gaps, exercises the SOCKS5 TCP/auth path end-to-end, and
implements a configurable client auto-reconnect for the TUIC outbound with tests.

Graceful shutdown:
- Unit tests for the server-core `acceptor_loop` cancellation primitive plus
  `is_tuic_prefix`/`read_prefix` (wind-tuic server core).
- Integration tests that the TUIC inbound listen loop and per-connection tasks
  drain on cancel; same for the SOCKS5 inbound accept loop and the tuic-client
  TCP/UDP forwarders.

Pure-function coverage:
- wind-core `is_private_ip`, `StackPrefer::from_str`, `pick_addr_by_preference`,
  `filter_addrs_by_preference`.
- wind-socks `parse_udp_request_sync`, `unmap_v4_mapped`, `target_addr_to_socket`,
  `convert_addr`/`convert_to_socks_addr` round-trips.
- wind-base `resolve_target` (IP-literal bypass + domain via resolver).

SOCKS5 TCP end-to-end (dependency-free client): no-auth + password auth
(right/wrong), IPv4 and domain CONNECT with echo round-trip, unsupported-command.

Client reconnect (new feature):
- TuicOutbound now holds the connection in an `ArcSwap`; a supervisor task runs
  one session until the connection drops, then reconnects with exponential
  backoff and swaps the fresh connection in. Shutdown is honored even mid-
  handshake. In-flight streams are not resurrected (callers retry).
- Reconnect is configurable via `ReconnectConfig` (enabled + backoff bounds),
  wired from the client `Relay` config with serde defaults (backward compatible).
- Tests: pure `next_backoff`, reconnect-after-restart, shutdown-while-reconnecting,
  reconnect-disabled, and config parsing/defaults.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
'CONNECTed' tokenizes as 'CONNEC'+'Ted'; the typos CI flagged 'CONNEC'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Itsusinn Itsusinn merged commit c534762 into main Jun 15, 2026
17 checks passed
@Itsusinn Itsusinn deleted the test/coverage-graceful-shutdown-reconnect branch June 15, 2026 14:15
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.

1 participant