1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #899 from aboch/sz

Handle concurrent creation of default GW network
This commit is contained in:
Jana Radhakrishnan 2016-01-25 17:45:28 -08:00
commit a63a935fb3

View file

@ -12,6 +12,8 @@ const (
gwEPlen = 12 gwEPlen = 12
) )
var procGwNetwork = make(chan (bool), 1)
/* /*
libnetwork creates a bridge network "docker_gw_bridge" for provding libnetwork creates a bridge network "docker_gw_bridge" for provding
default gateway for the containers if none of the container's endpoints default gateway for the containers if none of the container's endpoints
@ -35,13 +37,11 @@ func (sb *sandbox) setupDefaultGW(srcEp *endpoint) error {
return nil return nil
} }
// Look for default gw network. In case of error (includes not found),
// retry and create it if needed in a serialized execution.
n, err := c.NetworkByName(libnGWNetwork) n, err := c.NetworkByName(libnGWNetwork)
if err != nil { if err != nil {
if _, ok := err.(types.NotFoundError); !ok { if n, err = c.defaultGwNetwork(); err != nil {
return err
}
n, err = c.createGWNetwork()
if err != nil {
return err return err
} }
} }
@ -150,3 +150,18 @@ func (sb *sandbox) getEPwithoutGateway() *endpoint {
} }
return nil return nil
} }
// Looks for the default gw network and creates it if not there.
// Parallel executions are serialized.
func (c *controller) defaultGwNetwork() (Network, error) {
procGwNetwork <- true
defer func() { <-procGwNetwork }()
n, err := c.NetworkByName(libnGWNetwork)
if err != nil {
if _, ok := err.(types.NotFoundError); ok {
n, err = c.createGWNetwork()
}
}
return n, err
}