From 4f1b227ca2416e20f0067c898e58d9d1a6a34d43 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sat, 8 Jan 2022 09:23:49 +0800 Subject: [PATCH] [Style] Positive health check --- adapter/outboundgroup/fallback.go | 7 +++++-- adapter/outboundgroup/urltest.go | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/adapter/outboundgroup/fallback.go b/adapter/outboundgroup/fallback.go index 5f365ff8..734bd6b7 100644 --- a/adapter/outboundgroup/fallback.go +++ b/adapter/outboundgroup/fallback.go @@ -66,17 +66,20 @@ func (f *Fallback) onDialFailed() { f.failedTime.Store(now) f.failedTimes.Store(1) } else { - if f.failedTime.Load()-time.Now().UnixMilli() > 5*1000 { + if f.failedTime.Load()-time.Now().UnixMilli() > 5*time.Second.Milliseconds() { f.failedTimes.Store(-1) f.failedTime.Store(-1) } else { failedCount := f.failedTimes.Inc() log.Warnln("%s failed count: %d", f.Name(), failedCount) - if failedCount > 5 { + if failedCount >= 5 && failedCount < 6 { log.Warnln("because %s failed multiple times, active health check", f.Name()) for _, proxyProvider := range f.providers { go proxyProvider.HealthCheck() } + + f.failedTimes.Store(-1) + f.failedTime.Store(-1) } } } diff --git a/adapter/outboundgroup/urltest.go b/adapter/outboundgroup/urltest.go index c0ac5d3c..836dcaac 100644 --- a/adapter/outboundgroup/urltest.go +++ b/adapter/outboundgroup/urltest.go @@ -149,11 +149,14 @@ func (u *URLTest) onDialFailed() { } else { failedCount := u.failedTimes.Inc() log.Warnln("%s failed count: %d", u.Name(), failedCount) - if failedCount > 5 { + if failedCount >= 5 && failedCount < 6 { log.Warnln("because %s failed multiple times, active health check", u.Name()) for _, proxyProvider := range u.providers { go proxyProvider.HealthCheck() } + + u.failedTimes.Store(-1) + u.failedTime.Store(-1) } } }