From 42baed8b8fe480ea136bc63a3b88de37418e92c1 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Sat, 11 Sep 2021 02:37:32 +0800 Subject: [PATCH] Catch HttpConnectAsync's exception --- Netch/Controllers/MainController.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 1bf80a06..fa332191 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -34,7 +34,7 @@ namespace Netch.Controllers if (await DnsUtils.LookupAsync(server.Hostname) == null) throw new MessageException(i18N.Translate("Lookup Server hostname failed")); - + // TODO Disable NAT Type Test setting // cache STUN Server ip to prevent "Wrong STUN Server" DnsUtils.LookupAsync(Global.Settings.STUN_Server).Forget(); @@ -182,7 +182,20 @@ namespace Netch.Controllers public static async Task HttpConnectAsync(CancellationToken ctx = default) { Debug.Assert(Socks5Server != null, nameof(Socks5Server) + " != null"); - return await Socks5ServerTestUtils.HttpConnectAsync(Socks5Server, ctx); + try + { + return await Socks5ServerTestUtils.HttpConnectAsync(Socks5Server, ctx); + } + catch (OperationCanceledException) + { + // ignored + } + catch (Exception e) + { + Log.Warning(e, "Unhandled Socks5ServerTestUtils.HttpConnectAsync Exception"); + } + + return null; } } } \ No newline at end of file