mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Prevent race between add-binding and net-delete
Lock the network ID in the controller during an addServiceBinding to prevent racing with network.delete(). This would cause the binding to be silently ignored in the system. Signed-off-by: Chris Telfer <ctelfer@docker.com>
This commit is contained in:
parent
ea2fa20859
commit
0b14b45f0c
1 changed files with 7 additions and 0 deletions
|
@ -225,6 +225,13 @@ func makeServiceCleanupFunc(c *controller, s *service, nID, eID string, vip net.
|
|||
func (c *controller) addServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases, taskAliases []string, ip net.IP, method string) error {
|
||||
var addService bool
|
||||
|
||||
// Failure to lock the network ID on add can result in racing
|
||||
// racing against network deletion resulting in inconsistent
|
||||
// state in the c.serviceBindings map and it's sub-maps. Also,
|
||||
// always lock network ID before services to avoid deadlock.
|
||||
c.networkLocker.Lock(nID)
|
||||
defer c.networkLocker.Unlock(nID)
|
||||
|
||||
n, err := c.NetworkByID(nID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue