Skip to content

Commit

Permalink
Merge pull request #738 from zhangshen023/etcd-lease
Browse files Browse the repository at this point in the history
Fix: add etcdv3 lease to defeat provider register info left in the registry when provider app  panic
  • Loading branch information
zouyx committed Sep 22, 2020
1 parent a23f4c9 commit 7672009
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion registry/etcdv3/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ func (r *etcdV3Registry) InitListeners() {
}

// DoRegister actually do the register job in the registry center of etcd
// for lease
func (r *etcdV3Registry) DoRegister(root string, node string) error {
return r.client.Create(path.Join(root, node), "")
return r.client.RegisterTemp(path.Join(root, node), "")
}

// nolint
Expand Down
3 changes: 2 additions & 1 deletion remoting/etcdv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ func (c *Client) keepAliveKV(k string, v string) error {
return ErrNilETCDV3Client
}

lease, err := c.rawClient.Grant(c.ctx, int64(time.Second.Seconds()))
// make lease time longer, since 1 second is too short
lease, err := c.rawClient.Grant(c.ctx, int64(30*time.Second.Seconds()))
if err != nil {
return perrors.WithMessage(err, "grant lease")
}
Expand Down

0 comments on commit 7672009

Please sign in to comment.