From f6efbe4b619b492e044c8a1dd65fe6c967d9ace9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 3 Oct 2025 22:27:49 +0800 Subject: [PATCH] fet(dns): auto-recover failed items --- dns/dns.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dns/dns.go b/dns/dns.go index ad3b192..8257869 100644 --- a/dns/dns.go +++ b/dns/dns.go @@ -31,6 +31,14 @@ type dnsstat struct { e bool } +func (ds *dnsstat) disable(reEnable time.Duration) { + ds.e = false + // re-enable after some times + time.AfterFunc(reEnable, func() { + ds.e = true + }) +} + type DNSList struct { sync.RWMutex m map[string][]*dnsstat @@ -105,7 +113,7 @@ func (ds *DNSList) lookupHostDoH(ctx context.Context, host string) ([]string, er return hosts, nil } } - addr.e = false // no need to acquire write lock + addr.disable(time.Hour) // no need to acquire write lock } } if addrs, ok := ds.b[host]; ok { @@ -141,7 +149,7 @@ func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer, firstFra } conn, err = dialer.DialContext(ctx, "tcp", addr.a) if err != nil { - addr.e = false // no need to acquire write lock + addr.disable(time.Hour) // no need to acquire write lock continue } tlsConn = tls.Client(conn, &tls.Config{ServerName: host}) @@ -150,7 +158,7 @@ func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer, firstFra return } _ = tlsConn.Close() - addr.e = false // no need to acquire write lock + addr.disable(time.Hour) // no need to acquire write lock } } return