Skip to content

Commit 080d967

Browse files
committed
storepool: prevent holding multiple mutexes in UpdateLocalStoresAfterLeaseTransfer
This commit mitigates a deadlock that could potentially happen if two calls to UpdateLocalStoresAfterLeaseTransfer happen simultaneously in different order -> Leading to a deadlock. Fixes: #145531 Release note: None
1 parent 44552e1 commit 080d967

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/kv/kvserver/allocator/storepool/store_pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ func (sp *StorePool) UpdateLocalStoresAfterLeaseTransfer(
647647
) {
648648
fromDetail := sp.GetStoreDetail(from)
649649
fromDetail.Lock()
650-
defer fromDetail.Unlock()
651650
if fromDetail.Desc != nil {
652651
fromDetail.Desc.Capacity.LeaseCount--
653652
if fromDetail.Desc.Capacity.QueriesPerSecond < rangeUsageInfo.QueriesPerSecond {
@@ -671,10 +670,10 @@ func (sp *StorePool) UpdateLocalStoresAfterLeaseTransfer(
671670

672671
sp.Details.StoreDetails.Store(from, fromDetail)
673672
}
673+
fromDetail.Unlock()
674674

675675
toDetail := sp.GetStoreDetail(to)
676676
toDetail.Lock()
677-
defer toDetail.Unlock()
678677
if toDetail.Desc != nil {
679678
toDetail.Desc.Capacity.LeaseCount++
680679
toDetail.Desc.Capacity.QueriesPerSecond += rangeUsageInfo.QueriesPerSecond
@@ -685,6 +684,7 @@ func (sp *StorePool) UpdateLocalStoresAfterLeaseTransfer(
685684
}
686685
sp.Details.StoreDetails.Store(to, toDetail)
687686
}
687+
toDetail.Unlock()
688688
}
689689

690690
// newStoreDetail makes a new StoreDetailMu struct.

0 commit comments

Comments
 (0)