Skip to content

Commit

Permalink
Merge pull request #22918 from tonistiigi/image-delete-deadlock
Browse files Browse the repository at this point in the history
Release memoryStore locks before filter/apply
  • Loading branch information
estesp committed May 26, 2016
2 parents 8e92415 + bd2b3d3 commit 67767db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
5 changes: 0 additions & 5 deletions container/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ func (history *History) Swap(i, j int) {
containers[i], containers[j] = containers[j], containers[i]
}

// Add the given container to history.
func (history *History) Add(container *Container) {
*history = append(*history, container)
}

// sort orders the history by creation date in descendant order.
func (history *History) sort() {
sort.Sort(history)
Expand Down
28 changes: 14 additions & 14 deletions container/memory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,9 @@ func (c *memoryStore) Delete(id string) {
// List returns a sorted list of containers from the store.
// The containers are ordered by creation date.
func (c *memoryStore) List() []*Container {
containers := new(History)
c.RLock()
for _, cont := range c.s {
containers.Add(cont)
}
c.RUnlock()
containers := History(c.all())
containers.sort()
return *containers
return containers
}

// Size returns the number of containers in the store.
Expand All @@ -60,9 +55,7 @@ func (c *memoryStore) Size() int {

// First returns the first container found in the store by a given filter.
func (c *memoryStore) First(filter StoreFilter) *Container {
c.RLock()
defer c.RUnlock()
for _, cont := range c.s {
for _, cont := range c.all() {
if filter(cont) {
return cont
}
Expand All @@ -74,11 +67,8 @@ func (c *memoryStore) First(filter StoreFilter) *Container {
// This operation is asyncronous in the memory store.
// NOTE: Modifications to the store MUST NOT be done by the StoreReducer.
func (c *memoryStore) ApplyAll(apply StoreReducer) {
c.RLock()
defer c.RUnlock()

wg := new(sync.WaitGroup)
for _, cont := range c.s {
for _, cont := range c.all() {
wg.Add(1)
go func(container *Container) {
apply(container)
Expand All @@ -89,4 +79,14 @@ func (c *memoryStore) ApplyAll(apply StoreReducer) {
wg.Wait()
}

func (c *memoryStore) all() []*Container {
c.RLock()
containers := make([]*Container, 0, len(c.s))
for _, cont := range c.s {
containers = append(containers, cont)
}
c.RUnlock()
return containers
}

var _ Store = &memoryStore{}

0 comments on commit 67767db

Please sign in to comment.