[Fixed] Positive health check multithreading is not safe

This commit is contained in:
Skyxim 2022-01-07 12:58:40 +08:00
parent d35d6c9ac9
commit 75b5f633cd
2 changed files with 4 additions and 6 deletions

View File

@ -70,11 +70,10 @@ func (f *Fallback) onDialFailed() {
f.failedTimes.Store(-1)
f.failedTime.Store(-1)
} else {
f.failedTimes.Inc()
failedCount := f.failedTimes.Load()
failedCount := f.failedTimes.Inc()
log.Warnln("%s failed count: %d", f.Name(), failedCount)
if failedCount > 5 {
log.Debugln("%s failed multiple times.", f.Name())
log.Warnln("because %s failed multiple times, active health check", f.Name())
for _, proxyProvider := range f.providers {
go proxyProvider.HealthCheck()
}

View File

@ -147,11 +147,10 @@ func (u *URLTest) onDialFailed() {
u.failedTimes.Store(-1)
u.failedTime.Store(-1)
} else {
u.failedTimes.Inc()
failedCount := u.failedTimes.Load()
failedCount := u.failedTimes.Inc()
log.Warnln("%s failed count: %d", u.Name(), failedCount)
if failedCount > 5 {
log.Debugln("%s failed multiple times.", u.Name())
log.Warnln("because %s failed multiple times, active health check", u.Name())
for _, proxyProvider := range u.providers {
go proxyProvider.HealthCheck()
}