From 1db3fa0fa230181b7d49296d9b4872290b2e137d Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 4 Dec 2023 12:39:29 +0000 Subject: [PATCH] Rollback the pull/14080: which fixed the potential deadlock Signed-off-by: Benjamin Wang --- server/lease/lessor.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/lease/lessor.go b/server/lease/lessor.go index db738efcc314..2302c538e4e0 100644 --- a/server/lease/lessor.go +++ b/server/lease/lessor.go @@ -322,11 +322,6 @@ func (le *lessor) Revoke(id LeaseID) error { return ErrLeaseNotFound } - // We shouldn't delete the lease inside the transaction lock, otherwise - // it may lead to deadlock with Grant or Checkpoint operations, which - // acquire the le.mu firstly and then the batchTx lock. - delete(le.leaseMap, id) - defer close(l.revokec) // unlock before doing external work le.mu.Unlock() @@ -345,6 +340,9 @@ func (le *lessor) Revoke(id LeaseID) error { txn.DeleteRange([]byte(key), nil) } + le.mu.Lock() + defer le.mu.Unlock() + delete(le.leaseMap, l.ID) // lease deletion needs to be in the same backend transaction with the // kv deletion. Or we might end up with not executing the revoke or not // deleting the keys if etcdserver fails in between.