VETH interface cleanup when dockerD suddenly crashes

VETH interface was not cleaned up when DockerD got killed between addEndpoint and updateToStore calls.
I have added logs and made sure calling updateToStore before addEndpoint contains same values.
Hence moving up the call looks safer and VETH gets cleaned up even after DockerD gets killed in the middle.

Signed-off-by: selansen <elango@docker.com>
This commit is contained in:
selansen 2017-12-06 14:45:00 -08:00
parent b1ff9f5acb
commit 66b65b471a

View file

@ -1156,6 +1156,18 @@ func (n *network) createEndpoint(name string, options ...EndpointOption) (Endpoi
ep.releaseAddress()
}
}()
// Moving updateToSTore before calling addEndpoint so that we shall clean up VETH interfaces in case
// DockerD get killed between addEndpoint and updateSTore call
if err = n.getController().updateToStore(ep); err != nil {
return nil, err
}
defer func() {
if err != nil {
if e := n.getController().deleteFromStore(ep); e != nil {
logrus.Warnf("error rolling back endpoint %s from store: %v", name, e)
}
}
}()
if err = n.addEndpoint(ep); err != nil {
return nil, err
@ -1172,17 +1184,6 @@ func (n *network) createEndpoint(name string, options ...EndpointOption) (Endpoi
return nil, err
}
if err = n.getController().updateToStore(ep); err != nil {
return nil, err
}
defer func() {
if err != nil {
if e := n.getController().deleteFromStore(ep); e != nil {
logrus.Warnf("error rolling back endpoint %s from store: %v", name, e)
}
}
}()
// Watch for service records
n.getController().watchSvcRecord(ep)
defer func() {