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

fix(dns): not disable on no network

This commit is contained in:
源文雨
2025-10-06 16:07:03 +08:00
parent 797803b382
commit 541b84ca4a

View File

@@ -7,6 +7,7 @@ import (
"net" "net"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"github.com/fumiama/terasu" "github.com/fumiama/terasu"
@@ -171,7 +172,9 @@ func (ds *DNSList) lookupHostDoH(ctx context.Context, host string) (hosts []stri
return ErrSuccess return ErrSuccess
} }
} }
if !errors.Is(err, context.Canceled) { if !errors.Is(err, context.Canceled) &&
!errors.Is(err, syscall.ENETUNREACH) &&
!errors.Is(err, syscall.ENETDOWN) {
addr.disable(time.Hour) // no need to acquire write lock addr.disable(time.Hour) // no need to acquire write lock
} }
} }
@@ -218,7 +221,9 @@ func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer, firstFra
conn, err = dialer.DialContext(ctx, "tcp", addr.addr) conn, err = dialer.DialContext(ctx, "tcp", addr.addr)
if err != nil { if err != nil {
logrus.Debugln("[terasu.dns] -- dial tcp", host, addr, "err:", err) logrus.Debugln("[terasu.dns] -- dial tcp", host, addr, "err:", err)
if !errors.Is(err, context.Canceled) { if !errors.Is(err, context.Canceled) &&
!errors.Is(err, syscall.ENETUNREACH) &&
!errors.Is(err, syscall.ENETDOWN) {
addr.disable(time.Hour) // no need to acquire write lock addr.disable(time.Hour) // no need to acquire write lock
} }
continue continue
@@ -255,7 +260,9 @@ func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer, firstFra
} }
logrus.Debugln("[terasu.dns] -- hs tls", host, addr, "err:", err) logrus.Debugln("[terasu.dns] -- hs tls", host, addr, "err:", err)
_ = tlsConn.Close() _ = tlsConn.Close()
if !errors.Is(err, context.Canceled) { if !errors.Is(err, context.Canceled) &&
!errors.Is(err, syscall.ENETUNREACH) &&
!errors.Is(err, syscall.ENETDOWN) {
logrus.Debugln("[terasu.dns] == disable", host, addr) logrus.Debugln("[terasu.dns] == disable", host, addr)
addr.disable(time.Hour) // no need to acquire write lock addr.disable(time.Hour) // no need to acquire write lock
} }