Skip to content

Commit

Permalink
积极的健康检查
Browse files Browse the repository at this point in the history
  • Loading branch information
taikulawo committed Mar 23, 2024
1 parent 02fc7f5 commit 3a8d470
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 10 additions & 2 deletions adapter/outboundgroup/groupbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ func (gb *GroupBase) onDialFailed(adapterType C.AdapterType, err error) {

gb.failedTimes++
if gb.failedTimes == 1 {
log.Debugln("ProxyGroup: %s first failed", gb.Name())
log.Debugln("ProxyGroup: %s first failed, async healthchecking", gb.Name())
gb.failedTime = time.Now()
// 一段时间内首次报错马上健康检查
// 避免流量太低,始终无法触发检查,一直使用失败的连接。
// 重新找到可用的链接,避免 cafecat 备用地址 profile
gb.onlyHealthCheck()
} else {
if time.Since(gb.failedTime) > gb.failedTimeoutInterval() {
gb.failedTimes = 0
Expand All @@ -255,6 +259,11 @@ func (gb *GroupBase) onDialFailed(adapterType C.AdapterType, err error) {
}

func (gb *GroupBase) healthCheck() {
gb.onlyHealthCheck()
gb.failedTimes = 0
}

func (gb *GroupBase) onlyHealthCheck() {
if gb.failedTesting.Load() {
return
}
Expand All @@ -272,7 +281,6 @@ func (gb *GroupBase) healthCheck() {

wg.Wait()
gb.failedTesting.Store(false)
gb.failedTimes = 0
}

func (gb *GroupBase) failedIntervalTime() int64 {
Expand Down
1 change: 0 additions & 1 deletion adapter/outboundgroup/urltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,5 @@ func NewURLTest(option *GroupCommonOption, providers []provider.ProxyProvider, o
for _, option := range options {
option(urlTest)
}

return urlTest
}

0 comments on commit 3a8d470

Please sign in to comment.