From 94e52b072950910a44195a2b76a625eac7b99331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Mon, 29 Nov 2021 14:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A88.8.8.8dns=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.DomainResolve/DnsClient.cs | 7 ++++--- FastGithub/appsettings.json | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index 3b0a2bf..54911f1 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Options; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; @@ -33,7 +34,7 @@ namespace FastGithub.DomainResolve private readonly ConcurrentDictionary semaphoreSlims = new(); private readonly IMemoryCache dnsLookupCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); - private readonly TimeSpan minTimeToLive = TimeSpan.FromSeconds(30d); + private readonly TimeSpan minTimeToLive = TimeSpan.FromMinutes(1d); private readonly TimeSpan maxTimeToLive = TimeSpan.FromMinutes(10d); private readonly int resolveTimeout = (int)TimeSpan.FromSeconds(4d).TotalMilliseconds; @@ -130,10 +131,10 @@ namespace FastGithub.DomainResolve { return Array.Empty(); } - catch (SocketException ex) + catch (IOException ex) when (ex.InnerException is SocketException) { this.logger.LogWarning($"{endPoint.Host}@{dns}->{ex.Message}"); - return this.dnsLookupCache.Set(key, Array.Empty(), this.minTimeToLive); + return this.dnsLookupCache.Set(key, Array.Empty(), this.maxTimeToLive); } catch (Exception ex) { diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index c75cf82..08a200e 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -3,8 +3,8 @@ "FastGithub": { "HttpProxyPort": 38457, // http代理端口,linux/osx平台使用 "FallbackDns": [ // 以下dns必须要支持tcp - "114.114.114.114:53", - "119.29.29.29:53" + "8.8.8.8:53", + "114.114.114.114:53" ], "DomainConfigs": { "*.fastgithub.com": { // 域名的*表示除.之外0到多个任意字符