From 271aa92890b2fd6da7c2570fccfa6cfc39fb337a Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Wed, 31 May 2017 14:52:43 -0400 Subject: [PATCH] Lock container while connecting to a new network. `ConnectToNetwork` is modfying the container but is not locking the object. Signed-off-by: Brian Goff (cherry picked from commit 4d0888e32bccfd8c0f27a7b66b2a5607d42e2698) Signed-off-by: Brian Goff --- components/engine/daemon/container_operations.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/engine/daemon/container_operations.go b/components/engine/daemon/container_operations.go index 82ca4701af..1b6f02d0a1 100644 --- a/components/engine/daemon/container_operations.go +++ b/components/engine/daemon/container_operations.go @@ -980,6 +980,9 @@ func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName if endpointConfig == nil { endpointConfig = &networktypes.EndpointSettings{} } + container.Lock() + defer container.Unlock() + if !container.Running { if container.RemovalInProgress || container.Dead { return errRemovalContainer(container.ID) @@ -1002,7 +1005,7 @@ func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName return err } } - if err := container.ToDiskLocking(); err != nil { + if err := container.ToDisk(); err != nil { return fmt.Errorf("Error saving container to disk: %v", err) } return nil @@ -1011,6 +1014,9 @@ func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName // DisconnectFromNetwork disconnects container from network n. func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, networkName string, force bool) error { n, err := daemon.FindNetwork(networkName) + container.Lock() + defer container.Unlock() + if !container.Running || (err != nil && force) { if container.RemovalInProgress || container.Dead { return errRemovalContainer(container.ID) @@ -1038,7 +1044,7 @@ func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, netw return err } - if err := container.ToDiskLocking(); err != nil { + if err := container.ToDisk(); err != nil { return fmt.Errorf("Error saving container to disk: %v", err) }