Skip to content

Commit

Permalink
util/mon: don't crash when shrinking by too much
Browse files Browse the repository at this point in the history
Previously, we called `panic` when `Shrink`ing the memory account by
too much. Such scenario indicates that our memory accounting is off,
but we shouldn't be crashing - we should report an error instead, and
this commit does that.

Release note (bug fix): Previously, CockroachDB could crash when
internal memory accounting hit a discrepancy. Now it will report an
error instead.
  • Loading branch information
yuzefovich committed Jul 6, 2020
1 parent d6ab02f commit 5d15763
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/util/mon/bytes_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,10 @@ func (b *BoundAccount) Grow(ctx context.Context, x int64) error {
// Shrink releases part of the cumulated allocations by the specified size.
func (b *BoundAccount) Shrink(ctx context.Context, delta int64) {
if b.used < delta {
panic(fmt.Sprintf("%s: no bytes in account to release, current %d, free %d",
b.mon.name, b.used, delta))
log.ReportOrPanic(ctx, &b.mon.settings.SV,
"%s: no bytes in account to release, current %d, free %d",
b.mon.name, b.used, delta)
delta = b.used
}
b.used -= delta
b.reserved += delta
Expand Down

0 comments on commit 5d15763

Please sign in to comment.