mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove race condition from ovnmanager
This one is probably not critical. The worst that seems like could happen would be if 2 deletes occur at the same time (one of which should be an error): 1. network gets read from the map by delete-1 2. network gets read from the map by delete-2 3. delete-1 releases the network VNI 4. network create arrives at the driver and allocates the now free VNI 5. delete-2 releases the network VNI (error: it's been reallocated!) 6. both networks remove the VNI from the map Part 6 could also become an issue if there were a simultaneous create for the network at the same time. This leads to the modification of the NewNetwork() method which now checks for an existing network before adding it to the map. Signed-off-by: Chris Telfer <ctelfer@docker.com>
This commit is contained in:
parent
b64997ea82
commit
40b55d2336
1 changed files with 6 additions and 4 deletions
|
@ -125,8 +125,12 @@ func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data,
|
|||
opts[netlabel.OverlayVxlanIDList] = val
|
||||
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
if _, ok := d.networks[id]; ok {
|
||||
n.releaseVxlanID()
|
||||
return nil, fmt.Errorf("network %s already exists", id)
|
||||
}
|
||||
d.networks[id] = n
|
||||
d.Unlock()
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
@ -137,8 +141,8 @@ func (d *driver) NetworkFree(id string) error {
|
|||
}
|
||||
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
n, ok := d.networks[id]
|
||||
d.Unlock()
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("overlay network with id %s not found", id)
|
||||
|
@ -147,9 +151,7 @@ func (d *driver) NetworkFree(id string) error {
|
|||
// Release all vxlan IDs in one shot.
|
||||
n.releaseVxlanID()
|
||||
|
||||
d.Lock()
|
||||
delete(d.networks, id)
|
||||
d.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue