Skip to content

Commit

Permalink
try keepalive 3 times
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Apr 5, 2024
1 parent e64d6cf commit d932108
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,28 @@ func (cr *Cluster) Enable(ctx context.Context) (err error) {
cr.waitEnable = cr.waitEnable[:0]
go cr.notifyManager.OnEnabled()

var keepaliveCtx context.Context
const maxFailCount = 3
var (
keepaliveCtx context.Context
failedCount = 0
)
keepaliveCtx, cr.cancelKeepalive = context.WithCancel(ctx)
createInterval(keepaliveCtx, func() {
tctx, cancel := context.WithTimeout(keepaliveCtx, KeepAliveInterval/2)
ok := cr.KeepAlive(tctx)
cancel()
if ok {
failedCount = 0
return
}
if keepaliveCtx.Err() == nil {
if tctx.Err() != nil {
failedCount++
log.Warnf("keep-alive failed (%d/%d)", failedCount, maxFailCount)
if failedCount < maxFailCount {
return
}
}
log.Info(Tr("info.cluster.reconnect.keepalive"))
cr.disable(ctx)
log.Info(Tr("info.cluster.reconnecting"))
Expand Down

0 comments on commit d932108

Please sign in to comment.