1
0
mirror of https://github.com/fumiama/terasu.git synced 2026-06-22 05:20:25 +08:00

fet(dns): auto-recover failed items

This commit is contained in:
源文雨
2025-10-03 22:27:49 +08:00
parent 9974bdca12
commit f6efbe4b61

View File

@@ -31,6 +31,14 @@ type dnsstat struct {
e bool 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 { type DNSList struct {
sync.RWMutex sync.RWMutex
m map[string][]*dnsstat m map[string][]*dnsstat
@@ -105,7 +113,7 @@ func (ds *DNSList) lookupHostDoH(ctx context.Context, host string) ([]string, er
return hosts, nil 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 { 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) conn, err = dialer.DialContext(ctx, "tcp", addr.a)
if err != nil { if err != nil {
addr.e = false // no need to acquire write lock addr.disable(time.Hour) // no need to acquire write lock
continue continue
} }
tlsConn = tls.Client(conn, &tls.Config{ServerName: host}) tlsConn = tls.Client(conn, &tls.Config{ServerName: host})
@@ -150,7 +158,7 @@ func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer, firstFra
return return
} }
_ = tlsConn.Close() _ = tlsConn.Close()
addr.e = false // no need to acquire write lock addr.disable(time.Hour) // no need to acquire write lock
} }
} }
return return