Skip to content

Commit

Permalink
cache: fix possible concurrent maps write on parent release
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Nov 12, 2019
1 parent 2a9b6b5 commit 31beb83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (cm *cacheManager) get(ctx context.Context, id string, fromSnapshotter bool
return nil, errors.Wrapf(ErrLocked, "%s is locked", id)
}
if rec.equalImmutable != nil {
rec.equalImmutable.mu.Lock()
defer rec.equalImmutable.mu.Unlock()
return rec.equalImmutable.ref(triggerUpdate), nil
}
return rec.mref(triggerUpdate).commit(ctx)
Expand Down
10 changes: 4 additions & 6 deletions cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ func (cr *cacheRecord) Mount(ctx context.Context, readonly bool) (snapshot.Mount
func (cr *cacheRecord) remove(ctx context.Context, removeSnapshot bool) error {
delete(cr.cm.records, cr.ID())
if cr.parent != nil {
if err := cr.parent.release(ctx); err != nil {
cr.parent.mu.Lock()
err := cr.parent.release(ctx)
cr.parent.mu.Unlock()
if err != nil {
return err
}
}
Expand Down Expand Up @@ -401,11 +404,6 @@ func (sr *mutableRef) release(ctx context.Context) error {
return err
}
}
if sr.parent != nil {
if err := sr.parent.release(ctx); err != nil {
return err
}
}
return sr.remove(ctx, true)
} else {
if sr.updateLastUsed() {
Expand Down

0 comments on commit 31beb83

Please sign in to comment.