Skip to content

Commit

Permalink
util/memory: warn potential deadlock for Consume in remove (#16987) (#…
Browse files Browse the repository at this point in the history
…18394)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Jul 20, 2020
1 parent 6f0254c commit 2c2e308
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions util/memory/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,19 @@ func (t *Tracker) AttachTo(parent *Tracker) {
}

func (t *Tracker) remove(oldChild *Tracker) {
found := false
t.mu.Lock()
defer t.mu.Unlock()
for i, child := range t.mu.children {
if child != oldChild {
continue
if child == oldChild {
t.mu.children = append(t.mu.children[:i], t.mu.children[i+1:]...)
found = true
break
}

t.Consume(-oldChild.BytesConsumed())
}
t.mu.Unlock()
if found {
oldChild.parent = nil
t.mu.children = append(t.mu.children[:i], t.mu.children[i+1:]...)
break
t.Consume(-oldChild.BytesConsumed())
}
}

Expand Down

0 comments on commit 2c2e308

Please sign in to comment.