Skip to content

Commit 4ce2c15

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 93518dd commit 4ce2c15

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
@@ -646,7 +646,6 @@ func (sp *StorePool) UpdateLocalStoresAfterLeaseTransfer(
646646
) {
647647
fromDetail := sp.GetStoreDetail(from)
648648
fromDetail.Lock()
649-
defer fromDetail.Unlock()
650649
if fromDetail.Desc != nil {
651650
fromDetail.Desc.Capacity.LeaseCount--
652651
if fromDetail.Desc.Capacity.QueriesPerSecond < rangeUsageInfo.QueriesPerSecond {
@@ -670,10 +669,10 @@ func (sp *StorePool) UpdateLocalStoresAfterLeaseTransfer(
670669

671670
sp.Details.StoreDetails.Store(from, fromDetail)
672671
}
672+
fromDetail.Unlock()
673673

674674
toDetail := sp.GetStoreDetail(to)
675675
toDetail.Lock()
676-
defer toDetail.Unlock()
677676
if toDetail.Desc != nil {
678677
toDetail.Desc.Capacity.LeaseCount++
679678
toDetail.Desc.Capacity.QueriesPerSecond += rangeUsageInfo.QueriesPerSecond
@@ -684,6 +683,7 @@ func (sp *StorePool) UpdateLocalStoresAfterLeaseTransfer(
684683
}
685684
sp.Details.StoreDetails.Store(to, toDetail)
686685
}
686+
toDetail.Unlock()
687687
}
688688

689689
// newStoreDetail makes a new StoreDetailMu struct.

0 commit comments

Comments
 (0)