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,