Skip to content

Commit

Permalink
fix: The intermittent abnormality of etcd has caused registration fai…
Browse files Browse the repository at this point in the history
…lure. (go-kratos#3464)
  • Loading branch information
liutengfei committed Nov 21, 2024
1 parent f8b97f6 commit acfdd14
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contrib/registry/etcd/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (r *Registry) heartBeat(ctx context.Context, leaseID clientv3.LeaseID, key
if curLeaseID == 0 {
// try to registerWithKV
var retreat []int
for retryCnt := 0; retryCnt < r.opts.maxRetry; retryCnt++ {
var retryCnt int
for retryCnt = 0; retryCnt < r.opts.maxRetry; retryCnt++ {
if ctx.Err() != nil {
return
}
Expand Down Expand Up @@ -202,7 +203,7 @@ func (r *Registry) heartBeat(ctx context.Context, leaseID clientv3.LeaseID, key
retreat = append(retreat, 1<<retryCnt)
time.Sleep(time.Duration(retreat[randSource.Intn(len(retreat))]) * time.Second)
}
if _, ok := <-kac; !ok {
if _, ok := <-kac; !ok && retryCnt >= r.opts.maxRetry {
// retry failed
return
}
Expand Down

0 comments on commit acfdd14

Please sign in to comment.