Browse code

Fixing panic when sandbox is nil

Signed-off-by: Pradip Dhara <pradipd@microsoft.com>

Pradip Dhara authored on 2017/09/26 07:21:37
Showing 1 changed files
... ...
@@ -525,18 +525,24 @@ func (daemon *Daemon) deleteLoadBalancerSandbox(n libnetwork.Network) {
525 525
 	if len(endpoints) == 1 {
526 526
 		sandboxName := n.Name() + "-sbox"
527 527
 
528
-		if err := endpoints[0].Info().Sandbox().DisableService(); err != nil {
529
-			logrus.Errorf("Failed to disable service on sandbox %s: %v", sandboxName, err)
530
-			//Ignore error and attempt to delete the load balancer endpoint
528
+		info := endpoints[0].Info()
529
+		if info != nil {
530
+			sb := info.Sandbox()
531
+			if sb != nil {
532
+				if err := sb.DisableService(); err != nil {
533
+					logrus.Warnf("Failed to disable service on sandbox %s: %v", sandboxName, err)
534
+					//Ignore error and attempt to delete the load balancer endpoint
535
+				}
536
+			}
531 537
 		}
532 538
 
533 539
 		if err := endpoints[0].Delete(true); err != nil {
534
-			logrus.Errorf("Failed to delete endpoint %s (%s) in %s: %v", endpoints[0].Name(), endpoints[0].ID(), sandboxName, err)
540
+			logrus.Warnf("Failed to delete endpoint %s (%s) in %s: %v", endpoints[0].Name(), endpoints[0].ID(), sandboxName, err)
535 541
 			//Ignore error and attempt to delete the sandbox.
536 542
 		}
537 543
 
538 544
 		if err := controller.SandboxDestroy(sandboxName); err != nil {
539
-			logrus.Errorf("Failed to delete %s sandbox: %v", sandboxName, err)
545
+			logrus.Warnf("Failed to delete %s sandbox: %v", sandboxName, err)
540 546
 			//Ignore error and attempt to delete the network.
541 547
 		}
542 548
 	}