chore: stop retry when couldn't find ip

This commit is contained in:
wwqgtxx
2024-01-02 21:49:27 +08:00
parent 33bc7914e9
commit 2e12ceeaed
2 changed files with 19 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package tunnel
import (
"context"
"errors"
"fmt"
"net"
"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) {
b := &backoff.Backoff{
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 {
fe(err)
}
if shouldStopRetry(err) {
return
}
select {
case <-time.After(b.Duration()):
continue