mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fixes a case of dangling endpoint during ungraceful daemon restart
When a container restarts after a ungraceful daemon restart, first cleanup any unclean sandbox before trying to allocate network resources. Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
ebf76171f6
commit
0c07096b7d
1 changed files with 20 additions and 8 deletions
|
@ -910,6 +910,13 @@ func createNetwork(controller libnetwork.NetworkController, dnet string, driver
|
|||
}
|
||||
|
||||
func (container *Container) allocateNetwork() error {
|
||||
sb := container.getNetworkSandbox()
|
||||
if sb != nil {
|
||||
// Cleanup any stale sandbox left over due to ungraceful daemon shutdown
|
||||
if err := sb.Delete(); err != nil {
|
||||
logrus.Errorf("failed to cleanup up stale network sandbox for container %s", container.ID)
|
||||
}
|
||||
}
|
||||
updateSettings := false
|
||||
if len(container.NetworkSettings.Networks) == 0 {
|
||||
mode := container.hostConfig.NetworkMode
|
||||
|
@ -936,6 +943,18 @@ func (container *Container) allocateNetwork() error {
|
|||
return container.writeHostConfig()
|
||||
}
|
||||
|
||||
func (container *Container) getNetworkSandbox() libnetwork.Sandbox {
|
||||
var sb libnetwork.Sandbox
|
||||
container.daemon.netController.WalkSandboxes(func(s libnetwork.Sandbox) bool {
|
||||
if s.ContainerID() == container.ID {
|
||||
sb = s
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return sb
|
||||
}
|
||||
|
||||
// ConnectToNetwork connects a container to a netork
|
||||
func (container *Container) ConnectToNetwork(idOrName string) error {
|
||||
if !container.Running {
|
||||
|
@ -1001,14 +1020,7 @@ func (container *Container) connectToNetwork(idOrName string, updateSettings boo
|
|||
return err
|
||||
}
|
||||
|
||||
var sb libnetwork.Sandbox
|
||||
controller.WalkSandboxes(func(s libnetwork.Sandbox) bool {
|
||||
if s.ContainerID() == container.ID {
|
||||
sb = s
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
sb := container.getNetworkSandbox()
|
||||
if sb == nil {
|
||||
options, err := container.buildSandboxOptions(n)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue