From 1770955d33ee3d8c2a7582dcb8563e8355c64e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E4=B9=9D?= <366193849@qq.com> Date: Sun, 19 Sep 2021 14:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=92=E5=BD=92=E6=9F=A5=E6=89=BETimedOut?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.Http/HttpClientHandler.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/FastGithub.Http/HttpClientHandler.cs b/FastGithub.Http/HttpClientHandler.cs index e55061b..d2c1447 100644 --- a/FastGithub.Http/HttpClientHandler.cs +++ b/FastGithub.Http/HttpClientHandler.cs @@ -126,9 +126,7 @@ namespace FastGithub.Http /// private void InterceptRequestException(HttpRequestMessage request, HttpRequestException exception) { - if (request.RequestUri == null || - exception.InnerException is not SocketException socketException || - socketException.SocketErrorCode != SocketError.TimedOut) + if (request.RequestUri == null || IsTimedOutSocketError(exception) == false) { return; } @@ -142,6 +140,21 @@ namespace FastGithub.Http { this.domainResolver.FlushDomain(new DnsEndPoint(request.Headers.Host, request.RequestUri.Port)); } + + + static bool IsTimedOutSocketError(HttpRequestException exception) + { + var inner = exception.InnerException; + while (inner != null) + { + if (inner is SocketException socketException && socketException.SocketErrorCode == SocketError.TimedOut) + { + return true; + } + inner = inner.InnerException; + } + return false; + } } ///