From 70ab27e4365d70670e7888832caff429f2163709 Mon Sep 17 00:00:00 2001 From: DHR60 <192860629+DHR60@users.noreply.github.com> Date: Sun, 1 Nov 2026 12:58:58 +0000 Subject: [PATCH] Fix udp test (#10484) --- v2rayN/ServiceLib.UdpTest/UdpTestService.cs | 9 +++------ v2rayN/ServiceLib/Services/SpeedtestService.cs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) 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());