diff --git a/adapter/adapter.go b/adapter/adapter.go index 1be877c7..2b3c7e6c 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -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 } diff --git a/adapter/outboundgroup/fallback.go b/adapter/outboundgroup/fallback.go index 8f5f539b..3e4c8927 100644 --- a/adapter/outboundgroup/fallback.go +++ b/adapter/outboundgroup/fallback.go @@ -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() { - return proxy - } - if proxy.Alive() { - al = proxy + for _, proxy := range proxies { + if len(f.selected) == 0 { + if proxy.Alive() { + return proxy + } + } else { + if proxy.Name() == f.selected { + if proxy.Alive() { + return proxy + } else { + f.selected = "" + } + } } } - return al + + return proxies[0] } func (f *Fallback) Set(name string) error { diff --git a/adapter/outboundgroup/groupbase.go b/adapter/outboundgroup/groupbase.go index eb383ab1..7754d220 100644 --- a/adapter/outboundgroup/groupbase.go +++ b/adapter/outboundgroup/groupbase.go @@ -151,6 +151,7 @@ func (gb *GroupBase) onDialFailed() { gb.failedTime = time.Now() } else { if time.Since(gb.failedTime) > gb.failedTimeoutInterval() { + gb.failedTimes = 0 return }