Fix first Tailscale connection fallback in Windows 0.3.14

This commit is contained in:
2026-11-13 12:31:22 +08:00
parent 839434a313
commit cf02204e35
5 changed files with 17 additions and 15 deletions
+7 -5
View File
@@ -107,16 +107,18 @@ internal static class TailnetTransport
token.ThrowIfCancellationRequested();
if (!IsTailnetAddress(address) || port is < 1 or > 65535) return false;
using var deadline = CancellationTokenSource.CreateLinkedTokenSource(token);
deadline.CancelAfter(TimeSpan.FromSeconds(1));
deadline.CancelAfter(TimeSpan.FromSeconds(5));
try
{
RequireProbeRoute(address);
using var ping = new Ping();
var reply = await ping.SendPingAsync(IPAddress.Parse(address), 1000).WaitAsync(deadline.Token).ConfigureAwait(false);
return reply.Status == IPStatus.Success;
// The first connection may need to establish a Tailscale path.
// Test the actual proxy listener instead of gating on ICMP.
using var socket = new TcpClient(AddressFamily.InterNetwork);
await socket.ConnectAsync(IPAddress.Parse(address), port, deadline.Token).ConfigureAwait(false);
return true;
}
catch (OperationCanceledException) when (!token.IsCancellationRequested) { return false; }
catch (Exception e) when (e is PingException or SocketException or NetworkInformationException
catch (Exception e) when (e is SocketException or NetworkInformationException
or InvalidOperationException or IOException or System.ComponentModel.Win32Exception) { return false; }
}