Skip to content

Commit

Permalink
Avoid race on network cleanup
Browse files Browse the repository at this point in the history
Use the locker to avoid the race between the network
deletion and new endpoints being created

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
  • Loading branch information
Flavio Crisciani committed Jun 17, 2017
1 parent 9a136c9 commit ee1326a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ func (n *network) delete(force bool) error {
id := n.id
n.Unlock()

c.networkLocker.Lock(id)
defer c.networkLocker.Unlock(id)

n, err := c.getNetworkFromStore(id)
if err != nil {
return &UnknownNetworkError{name: name, id: id}
Expand Down Expand Up @@ -1078,6 +1081,9 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
ep := &endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
ep.id = stringid.GenerateRandomID()

n.ctrlr.networkLocker.Lock(n.id)
defer n.ctrlr.networkLocker.Unlock(n.id)

// Initialize ep.network with a possibly stale copy of n. We need this to get network from
// store. But once we get it from store we will have the most uptodate copy possibly.
ep.network = n
Expand Down Expand Up @@ -1876,7 +1882,7 @@ func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) {
}

if ok && len(ipSet) > 0 {
// this maps is to avoid IP duplicates, this can happen during a transition period where 2 services are using the same IP
// this map is to avoid IP duplicates, this can happen during a transition period where 2 services are using the same IP
noDup := make(map[string]bool)
var ipLocal []net.IP
for _, ip := range ipSet {
Expand Down
4 changes: 2 additions & 2 deletions service_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *controller) addEndpointNameResolution(svcName, svcID, nID, eID, contain
return err
}

logrus.Debugf("addEndpointNameResolution %s %s add_service:%t", eID, svcName, addService)
logrus.Debugf("addEndpointNameResolution %s %s add_service:%t sAliases:%v tAliases:%v", eID, svcName, addService, serviceAliases, taskAliases)

// Add container resolution mappings
c.addContainerNameResolution(nID, eID, containerName, taskAliases, ip, method)
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *controller) deleteEndpointNameResolution(svcName, svcID, nID, eID, cont
return err
}

logrus.Debugf("deleteEndpointNameResolution %s %s rm_service:%t suppress:%t", eID, svcName, rmService, multipleEntries)
logrus.Debugf("deleteEndpointNameResolution %s %s rm_service:%t suppress:%t sAliases:%v tAliases:%v", eID, svcName, rmService, multipleEntries, serviceAliases, taskAliases)

// Delete container resolution mappings
c.delContainerNameResolution(nID, eID, containerName, taskAliases, ip, method)
Expand Down

0 comments on commit ee1326a

Please sign in to comment.