From a3ec549dbfbb6cd9ffb05af31f8cf172ab25f958 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 4 Dec 2021 00:16:39 +0800 Subject: [PATCH] Fixed: Modify the trigger condition, only if it fails successively --- adapter/outboundgroup/fallback.go | 14 +++++++++++--- adapter/outboundgroup/urltest.go | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/adapter/outboundgroup/fallback.go b/adapter/outboundgroup/fallback.go index 8651422d..4784cd3c 100644 --- a/adapter/outboundgroup/fallback.go +++ b/adapter/outboundgroup/fallback.go @@ -34,9 +34,12 @@ func (f *Fallback) DialContext(ctx context.Context, metadata *C.Metadata, opts . c, err := proxy.DialContext(ctx, metadata, f.Base.DialOptions(opts...)...) if err == nil { c.AppendToChains(f) + f.failedTimes.Store(-1) + f.failedTime.Store(-1) } else { f.onDialFailed() } + return c, err } @@ -46,9 +49,12 @@ func (f *Fallback) ListenPacketContext(ctx context.Context, metadata *C.Metadata pc, err := proxy.ListenPacketContext(ctx, metadata, f.Base.DialOptions(opts...)...) if err == nil { pc.AppendToChains(f) + f.failedTimes.Store(-1) + f.failedTime.Store(-1) } else { f.onDialFailed() } + return pc, err } @@ -132,8 +138,10 @@ func NewFallback(option *GroupCommonOption, providers []provider.ProxyProvider) Interface: option.Interface, RoutingMark: option.RoutingMark, }), - single: singledo.NewSingle(defaultGetProxiesDuration), - providers: providers, - disableUDP: option.DisableUDP, + single: singledo.NewSingle(defaultGetProxiesDuration), + providers: providers, + disableUDP: option.DisableUDP, + failedTimes: atomic.NewInt32(-1), + failedTime: atomic.NewInt64(-1), } } diff --git a/adapter/outboundgroup/urltest.go b/adapter/outboundgroup/urltest.go index 6bc15848..40d9f734 100644 --- a/adapter/outboundgroup/urltest.go +++ b/adapter/outboundgroup/urltest.go @@ -43,6 +43,8 @@ func (u *URLTest) DialContext(ctx context.Context, metadata *C.Metadata, opts .. c, err = u.fast(true).DialContext(ctx, metadata, u.Base.DialOptions(opts...)...) if err == nil { c.AppendToChains(u) + u.failedTimes.Store(-1) + u.failedTime.Store(-1) } else { u.onDialFailed() } @@ -55,6 +57,8 @@ func (u *URLTest) ListenPacketContext(ctx context.Context, metadata *C.Metadata, pc, err := u.fast(true).ListenPacketContext(ctx, metadata, u.Base.DialOptions(opts...)...) if err == nil { pc.AppendToChains(u) + u.failedTimes.Store(-1) + u.failedTime.Store(-1) } else { u.onDialFailed() }