From 86d44dcae64a2afc1d29ca60ca420ce6919f0ea4 Mon Sep 17 00:00:00 2001 From: Daniyar Ennanov <21172041+limeflash@users.noreply.github.com> Date: Tue, 1 Dec 2026 03:48:06 +0300 Subject: [PATCH] TrustTunnel: a TCP connect to the endpoint gives up after 5 s, not Windows' 21 Co-Authored-By: Claude Fable 5.2 --- core/internal/engine/trusttunnel_windows.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/internal/engine/trusttunnel_windows.go b/core/internal/engine/trusttunnel_windows.go index 97d38f3..fd80230 100644 --- a/core/internal/engine/trusttunnel_windows.go +++ b/core/internal/engine/trusttunnel_windows.go @@ -50,6 +50,9 @@ type ttOutbound struct { asking atomic.Bool // one _check at a time decides what a refused stream meant } +// ttDialTimeout is how long a TCP connect to a TrustTunnel endpoint may take. +const ttDialTimeout = 5 * time.Second + func startTT(ctx context.Context, p *profile.TrustTunnel, endpoints []netip.AddrPort) (*ttOutbound, error) { if p == nil || len(endpoints) == 0 { return nil, ttclient.ErrConfig @@ -72,6 +75,11 @@ func startTT(ctx context.Context, p *profile.TrustTunnel, endpoints []netip.Addr if err != nil { return nil, ttclient.ErrEndpoint } + // Windows gives a lost SYN 21 s before it says so. Seen live: a first attempt hung that long on a node whose + // network drops packets now and then, and the retry a second later connected at once. Two retransmissions + // fit in ttDialTimeout; after it the attempt fails and the session's own retry takes over. + ctx, cancel := context.WithTimeout(ctx, ttDialTimeout) + defer cancel() return (directOutbound{}).DialTCP(ctx, endpoint) }, ListenPacket: directPacketConn,