Get rid of lock during list containers (#2024)

* Get rid of lock during list containers
This commit is contained in:
Mikhail Shaverdo 2018-08-29 23:06:28 +03:00 committed by David Ashpole
parent 2fa6c624a2
commit fcc77c654b

View File

@ -1086,22 +1086,25 @@ func (m *manager) destroyContainerLocked(containerName string) error {
// Detect all containers that have been added or deleted from the specified container. // Detect all containers that have been added or deleted from the specified container.
func (m *manager) getContainersDiff(containerName string) (added []info.ContainerReference, removed []info.ContainerReference, err error) { func (m *manager) getContainersDiff(containerName string) (added []info.ContainerReference, removed []info.ContainerReference, err error) {
m.containersLock.RLock()
defer m.containersLock.RUnlock()
// Get all subcontainers recursively. // Get all subcontainers recursively.
m.containersLock.RLock()
cont, ok := m.containers[namespacedContainerName{ cont, ok := m.containers[namespacedContainerName{
Name: containerName, Name: containerName,
}] }]
m.containersLock.RUnlock()
if !ok { if !ok {
return nil, nil, fmt.Errorf("failed to find container %q while checking for new containers", containerName) return nil, nil, fmt.Errorf("failed to find container %q while checking for new containers", containerName)
} }
allContainers, err := cont.handler.ListContainers(container.ListRecursive) allContainers, err := cont.handler.ListContainers(container.ListRecursive)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
allContainers = append(allContainers, info.ContainerReference{Name: containerName}) allContainers = append(allContainers, info.ContainerReference{Name: containerName})
m.containersLock.RLock()
defer m.containersLock.RUnlock()
// Determine which were added and which were removed. // Determine which were added and which were removed.
allContainersSet := make(map[string]*containerData) allContainersSet := make(map[string]*containerData)
for name, d := range m.containers { for name, d := range m.containers {