Skip to content

Commit

Permalink
Merge pull request #105398 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1-105392

release-23.1: util/mon: fix deadlock
  • Loading branch information
mgartner committed Jun 23, 2023
2 parents 624d9de + f1344d7 commit a3e7f70
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/util/mon/bytes_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func (mm *BytesMonitor) doStop(ctx context.Context, check bool) {
ctx, &mm.settings.SV,
"%s: unexpected %d leftover bytes",
mm.name, mm.mu.curAllocated)
mm.releaseBytes(ctx, mm.mu.curAllocated)
mm.releaseBytesLocked(ctx, mm.mu.curAllocated)
}

mm.releaseBudget(ctx)
Expand Down Expand Up @@ -984,6 +984,13 @@ func (mm *BytesMonitor) reserveBytes(ctx context.Context, x int64) error {
func (mm *BytesMonitor) releaseBytes(ctx context.Context, sz int64) {
mm.mu.Lock()
defer mm.mu.Unlock()
mm.releaseBytesLocked(ctx, sz)
}

// releaseBytesLocked is similar to releaseBytes but requires that mm.mu has
// already been locked.
func (mm *BytesMonitor) releaseBytesLocked(ctx context.Context, sz int64) {
mm.mu.AssertHeld()
if mm.mu.curAllocated < sz {
logcrash.ReportOrPanic(ctx, &mm.settings.SV,
"%s: no bytes to release, current %d, free %d",
Expand Down

0 comments on commit a3e7f70

Please sign in to comment.