Skip to content

Commit a636200

Browse files
committed
catalog/lease: fix race condition releasing old versions
Previously, a race condition existed between the name cache and the logic used to clean up old versions of leased descriptors. This issue was introduced when atomic operations were used to manipulate the descriptor version states. Specifically, after ensuring the reference count is zero, it's necessary to acquire a lock before releasing the stored lease. This patch adds logic to acquire and release a mutex when cleaning up old versions. Fixes: #143815 Release note: None
1 parent ab84c1d commit a636200

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/sql/catalog/lease/descriptor_state.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,15 @@ func (t *descriptorState) removeInactiveVersions() []*storedLease {
203203
for _, desc := range append([]*descriptorVersionState(nil), t.mu.active.data...) {
204204
if desc.refcount.Load() == 0 {
205205
t.mu.active.remove(desc)
206-
if l := desc.mu.lease; l != nil {
207-
desc.mu.lease = nil
208-
leases = append(leases, l)
209-
}
206+
func() {
207+
desc.mu.Lock()
208+
defer desc.mu.Unlock()
209+
if l := desc.mu.lease; l != nil {
210+
desc.mu.lease = nil
211+
leases = append(leases, l)
212+
213+
}
214+
}()
210215
}
211216
}
212217
return leases

0 commit comments

Comments
 (0)