diff --git a/v2rayN/ServiceLib.UdpTest/UdpTestService.cs b/v2rayN/ServiceLib.UdpTest/UdpTestService.cs index b27aa542..d0e06e70 100644 --- a/v2rayN/ServiceLib.UdpTest/UdpTestService.cs +++ b/v2rayN/ServiceLib.UdpTest/UdpTestService.cs @@ -135,16 +135,13 @@ public class UdpTestService roundTripTime = currentRoundTripTime; } } - catch (OperationCanceledException) when (timeoutCts.IsCancellationRequested) + catch (OperationCanceledException) when (ct.IsCancellationRequested) { throw; } - catch + catch (OperationCanceledException) { - if (attempt == 1 && roundTripTime == TimeSpan.MaxValue) - { - throw; - } + // Timeout, continue to next attempt } } diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index ef5c4582..7c94f0d3 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -541,8 +541,20 @@ public class SpeedtestService(Config config, Func updateF private async Task DoUdpTest(ServerTestItem it, ConcurrentDictionary completedIds, CancellationToken ct = default) { - var udpService = UdpTestService.CreateFromTarget(_config?.SpeedTestItem.UdpTestTarget, out var udpTestUrl); - var responseTime = (int)(await udpService.SendUdpRequestAsync(udpTestUrl, it.Port, ct)).TotalMilliseconds; + var responseTime = -1; + try + { + var udpService = UdpTestService.CreateFromTarget(_config?.SpeedTestItem.UdpTestTarget, out var udpTestUrl); + responseTime = (int)(await udpService.SendUdpRequestAsync(udpTestUrl, it.Port, ct)).TotalMilliseconds; + } + catch (OperationCanceledException) when (ct.IsCancellationRequested) + { + throw; + } + catch + { + // Ignore + } ProfileExManager.Instance.SetTestDelay(it.IndexId, responseTime); await UpdateFunc(it.IndexId, responseTime.ToString());