Skip to content

Commit

Permalink
Hold the layer store lock while diffing
Browse files Browse the repository at this point in the history
While generating a Diff, hold the lock on the layer store until after
we've completely finished building the diff.

There's an internal Mount/Unmount being done so that we can read the
layer's contents, and we don't update the mount counts properly if we're
not still holding the lock when the layer store's Unmount() method is
called, which doesn't happen until the ReadCloser that Diff() returns
gets closed.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind committed Sep 13, 2018
1 parent 243c4cd commit 3df3c9f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2369,13 +2369,23 @@ func (s *store) Diff(from, to string, options *DiffOptions) (io.ReadCloser, erro
}
for _, store := range append([]ROLayerStore{lstore}, lstores...) {
store.Lock()
defer store.Unlock()
if modified, err := store.Modified(); modified || err != nil {
store.Load()
}
if store.Exists(to) {
return store.Diff(from, to, options)
rc, err := store.Diff(from, to, options)
if rc != nil && err == nil {
wrapped := ioutils.NewReadCloserWrapper(rc, func() error {
err := rc.Close()
store.Unlock()
return err
})
return wrapped, nil
}
store.Unlock()
return rc, err
}
store.Unlock()
}
return nil, ErrLayerUnknown
}
Expand Down

0 comments on commit 3df3c9f

Please sign in to comment.