fix: Temporarily delete marking node alive as false when error occurs
This commit is contained in:
parent
3e649ae8e8
commit
545af5d11c
3 changed files with 16 additions and 16 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
"net/http"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/atomic"
|
||||
|
@ -40,11 +39,6 @@ func (p *Proxy) Dial(metadata *C.Metadata) (C.Conn, error) {
|
|||
// DialContext implements C.ProxyAdapter
|
||||
func (p *Proxy) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
|
||||
conn, err := p.ProxyAdapter.DialContext(ctx, metadata, opts...)
|
||||
wasCancel := false
|
||||
if err != nil {
|
||||
wasCancel = strings.Contains(err.Error(), "operation was canceled")
|
||||
}
|
||||
p.alive.Store(err == nil || wasCancel)
|
||||
return conn, err
|
||||
}
|
||||
|
||||
|
@ -58,7 +52,6 @@ func (p *Proxy) DialUDP(metadata *C.Metadata) (C.PacketConn, error) {
|
|||
// ListenPacketContext implements C.ProxyAdapter
|
||||
func (p *Proxy) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) {
|
||||
pc, err := p.ProxyAdapter.ListenPacketContext(ctx, metadata, opts...)
|
||||
p.alive.Store(err == nil)
|
||||
return pc, err
|
||||
}
|
||||
|
||||
|
|
|
@ -79,17 +79,23 @@ func (f *Fallback) Unwrap(metadata *C.Metadata) C.Proxy {
|
|||
|
||||
func (f *Fallback) findAliveProxy(touch bool) C.Proxy {
|
||||
proxies := f.GetProxies(touch)
|
||||
al := proxies[0]
|
||||
for i := len(proxies) - 1; i > -1; i-- {
|
||||
proxy := proxies[i]
|
||||
if proxy.Name() == f.selected && proxy.Alive() {
|
||||
for _, proxy := range proxies {
|
||||
if len(f.selected) == 0 {
|
||||
if proxy.Alive() {
|
||||
return proxy
|
||||
}
|
||||
} else {
|
||||
if proxy.Name() == f.selected {
|
||||
if proxy.Alive() {
|
||||
al = proxy
|
||||
return proxy
|
||||
} else {
|
||||
f.selected = ""
|
||||
}
|
||||
}
|
||||
return al
|
||||
}
|
||||
}
|
||||
|
||||
return proxies[0]
|
||||
}
|
||||
|
||||
func (f *Fallback) Set(name string) error {
|
||||
|
|
|
@ -151,6 +151,7 @@ func (gb *GroupBase) onDialFailed() {
|
|||
gb.failedTime = time.Now()
|
||||
} else {
|
||||
if time.Since(gb.failedTime) > gb.failedTimeoutInterval() {
|
||||
gb.failedTimes = 0
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue