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

Fix error handling in createLoadBalncerSandbox()

Error unwinding only works if the error variable is used consistently
and isn't hidden in the scope of other if statements.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
This commit is contained in:
Chris Telfer 2018-04-09 23:46:22 -04:00
parent 1449e88f7a
commit 31d3de0994

View file

@ -2122,7 +2122,7 @@ func (n *network) lbEndpointName() string {
return n.name + "-endpoint" return n.name + "-endpoint"
} }
func (n *network) createLoadBalancerSandbox() error { func (n *network) createLoadBalancerSandbox() (retErr error) {
sandboxName := n.lbSandboxName() sandboxName := n.lbSandboxName()
sbOptions := []SandboxOption{} sbOptions := []SandboxOption{}
if n.ingress { if n.ingress {
@ -2133,9 +2133,9 @@ func (n *network) createLoadBalancerSandbox() error {
return err return err
} }
defer func() { defer func() {
if err != nil { if retErr != nil {
if e := n.ctrlr.SandboxDestroy(sandboxName); e != nil { if e := n.ctrlr.SandboxDestroy(sandboxName); e != nil {
logrus.Warnf("could not delete sandbox %s on failure on failure (%v): %v", sandboxName, err, e) logrus.Warnf("could not delete sandbox %s on failure on failure (%v): %v", sandboxName, retErr, e)
} }
} }
}() }()
@ -2150,9 +2150,9 @@ func (n *network) createLoadBalancerSandbox() error {
return err return err
} }
defer func() { defer func() {
if err != nil { if retErr != nil {
if e := ep.Delete(true); e != nil { if e := ep.Delete(true); e != nil {
logrus.Warnf("could not delete endpoint %s on failure on failure (%v): %v", endpointName, err, e) logrus.Warnf("could not delete endpoint %s on failure on failure (%v): %v", endpointName, retErr, e)
} }
} }
}() }()
@ -2160,6 +2160,7 @@ func (n *network) createLoadBalancerSandbox() error {
if err := ep.Join(sb, nil); err != nil { if err := ep.Join(sb, nil); err != nil {
return err return err
} }
return sb.EnableService() return sb.EnableService()
} }