mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
concurrency: only delete on election resignation if create revision matches
Addresses a case where two clients share the same lease. A client resigns but disconnects / crashes and doesn't realize it. Another client reuses the lease and gets leadership with a new key. The old client comes back and tries to resign again, revoking the new leadership of the new client.
This commit is contained in:
parent
4b5bb7f212
commit
d1ae4cd5bd
@ -115,7 +115,11 @@ func (e *Election) Resign(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
client := e.session.Client()
|
||||
_, err = client.Delete(ctx, e.leaderKey)
|
||||
cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev)
|
||||
resp, err := client.Txn(ctx).If(cmp).Then(v3.OpDelete(e.leaderKey)).Commit()
|
||||
if err == nil {
|
||||
e.hdr = resp.Header
|
||||
}
|
||||
e.leaderKey = ""
|
||||
e.leaderSession = nil
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user