fix: reconnect OpenVPN on server soft reset#2978
Conversation
|
Manual verification against the actual OpenVPN server:
This confirms that the reconnect fallback avoids the previous periodic blackhole until The live package predates the validation hardening in PR head |
|
I pushed a follow-up commit to keep the soft-reset lifecycle inside the OpenVPN client. Instead of exposing I made this change because soft resets and control epochs are transport-level protocol details that the outbound should not need to manage. After the handshake, the client starts an internal control watcher; when it detects a new key epoch or the control channel terminates, it closes the mux. The existing outbound data loop then performs the usual TUN and session cleanup. I also added tests covering automatic shutdown, ordinary control-message ACKs, pending-state cleanup, malformed packets, and session/key validation. |
|
Thanks for the follow-up. I rebuilt and deployed PR head Observation window: 2026-07-16 14:03-16:42 CST (about 2 hours 39 minutes).
This confirms in live use that the internal |
OpenVPN servers can send
P_CONTROL_SOFT_RESET_V1to begin data-channel key renegotiation. After the initial handshake, mihomo no longer reads the control stream, so the reset remains queued and the outbound can stop forwarding traffic untilping-restarttears down the session.Keep a post-handshake watcher on the raw control stream. When it receives a valid soft-reset packet for the current server session and a nonzero key epoch, close the client and TUN device; the existing lazy startup path performs a fresh handshake on the next request. Reading the raw stream is intentional because a new key epoch can reset message IDs, which the existing ordered control channel may otherwise treat as an old or duplicate message.
This is intentionally a reconnect fallback, not in-session key renegotiation. It restores the outbound without waiting for the keepalive timeout while keeping the change scoped to the existing session lifecycle. Existing connections can still be interrupted during the reconnect.
Tests:
go test ./...go test ./transport/openvpn ./adapter/outboundgo test -race ./transport/openvpngo vet ./transport/openvpn ./adapter/outboundCoverage includes plain,
tls-auth, andtls-cryptcontrol channels, plus malformed, initial-key, and wrong-session reset packets.