mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-14 14:08:04 +08:00
chore: stop retry when couldn't find ip
This commit is contained in:
parent
33bc7914e9
commit
2e12ceeaed
@ -289,8 +289,6 @@ func listenPacket(ctx context.Context, proxyAdapter C.ProxyAdapter, proxyName st
|
|||||||
return proxyAdapter.ListenPacketContext(ctx, metadata, opts...)
|
return proxyAdapter.ListenPacketContext(ctx, metadata, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errIPNotFound = errors.New("couldn't find ip")
|
|
||||||
|
|
||||||
func batchExchange(ctx context.Context, clients []dnsClient, m *D.Msg) (msg *D.Msg, cache bool, err error) {
|
func batchExchange(ctx context.Context, clients []dnsClient, m *D.Msg) (msg *D.Msg, cache bool, err error) {
|
||||||
cache = true
|
cache = true
|
||||||
fast, ctx := picker.WithTimeout[*D.Msg](ctx, resolver.DefaultDNSTimeout)
|
fast, ctx := picker.WithTimeout[*D.Msg](ctx, resolver.DefaultDNSTimeout)
|
||||||
@ -320,12 +318,12 @@ func batchExchange(ctx context.Context, clients []dnsClient, m *D.Msg) (msg *D.M
|
|||||||
case D.TypeAAAA:
|
case D.TypeAAAA:
|
||||||
if len(ips) == 0 {
|
if len(ips) == 0 {
|
||||||
noIpMsg = m
|
noIpMsg = m
|
||||||
return nil, errIPNotFound
|
return nil, resolver.ErrIPNotFound
|
||||||
}
|
}
|
||||||
case D.TypeA:
|
case D.TypeA:
|
||||||
if len(ips) == 0 {
|
if len(ips) == 0 {
|
||||||
noIpMsg = m
|
noIpMsg = m
|
||||||
return nil, errIPNotFound
|
return nil, resolver.ErrIPNotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package tunnel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -684,6 +685,19 @@ func getRules(metadata *C.Metadata) []C.Rule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldStopRetry(err error) bool {
|
||||||
|
if errors.Is(err, resolver.ErrIPNotFound) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if errors.Is(err, resolver.ErrIPVersion) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if errors.Is(err, resolver.ErrIPv6Disabled) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe func(err error)) (t T, err error) {
|
func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe func(err error)) (t T, err error) {
|
||||||
b := &backoff.Backoff{
|
b := &backoff.Backoff{
|
||||||
Min: 10 * time.Millisecond,
|
Min: 10 * time.Millisecond,
|
||||||
@ -697,6 +711,9 @@ func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe f
|
|||||||
if fe != nil {
|
if fe != nil {
|
||||||
fe(err)
|
fe(err)
|
||||||
}
|
}
|
||||||
|
if shouldStopRetry(err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case <-time.After(b.Duration()):
|
case <-time.After(b.Duration()):
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user