Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 68ce73f

Browse files
author
Vincent Demeester
authored
Merge pull request #489 from exekias/master
Fix race condition on containers retrieval
2 parents 1b708aa + 6dcb4a4 commit 68ce73f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

project/project_containers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package project
22

33
import (
44
"fmt"
5+
"sync"
56

67
"golang.org/x/net/context"
78

@@ -12,6 +13,8 @@ import (
1213
// the Filter struct.
1314
func (p *Project) Containers(ctx context.Context, filter Filter, services ...string) ([]string, error) {
1415
containers := []string{}
16+
var lock sync.Mutex
17+
1518
err := p.forEach(services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) {
1619
wrapper.Do(nil, events.NoEvent, events.NoEvent, func(service Service) error {
1720
serviceContainers, innerErr := service.Containers(ctx)
@@ -37,7 +40,9 @@ func (p *Project) Containers(ctx context.Context, filter Filter, services ...str
3740
return fmt.Errorf("Invalid container filter: %s", filter.State)
3841
}
3942
containerID := container.ID()
43+
lock.Lock()
4044
containers = append(containers, containerID)
45+
lock.Unlock()
4146
}
4247
return nil
4348
})

0 commit comments

Comments
 (0)