Skip to content

Commit fcc77c6

Browse files
mshaverdodashpole
authored andcommitted
Get rid of lock during list containers (#2024)
* Get rid of lock during list containers
1 parent 2fa6c62 commit fcc77c6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

manager/manager.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,22 +1086,25 @@ func (m *manager) destroyContainerLocked(containerName string) error {
10861086

10871087
// Detect all containers that have been added or deleted from the specified container.
10881088
func (m *manager) getContainersDiff(containerName string) (added []info.ContainerReference, removed []info.ContainerReference, err error) {
1089-
m.containersLock.RLock()
1090-
defer m.containersLock.RUnlock()
1091-
10921089
// Get all subcontainers recursively.
1090+
m.containersLock.RLock()
10931091
cont, ok := m.containers[namespacedContainerName{
10941092
Name: containerName,
10951093
}]
1094+
m.containersLock.RUnlock()
10961095
if !ok {
10971096
return nil, nil, fmt.Errorf("failed to find container %q while checking for new containers", containerName)
10981097
}
10991098
allContainers, err := cont.handler.ListContainers(container.ListRecursive)
1099+
11001100
if err != nil {
11011101
return nil, nil, err
11021102
}
11031103
allContainers = append(allContainers, info.ContainerReference{Name: containerName})
11041104

1105+
m.containersLock.RLock()
1106+
defer m.containersLock.RUnlock()
1107+
11051108
// Determine which were added and which were removed.
11061109
allContainersSet := make(map[string]*containerData)
11071110
for name, d := range m.containers {

0 commit comments

Comments
 (0)