[lxc-devel] [lxd/master] lxd/containers: Fix crash on container error

stgraber on Github lxc-bot at linuxcontainers.org
Tue Mar 13 17:34:10 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180313/0d36b847/attachment.bin>
-------------- next part --------------
From f5b21ce632b81bf4e95353b6fc9641d65daa2d90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 13 Mar 2018 13:06:14 -0400
Subject: [PATCH] lxd/containers: Fix crash on container error
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4326

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/containers_get.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lxd/containers_get.go b/lxd/containers_get.go
index 75c95400a..3a4fe94e4 100644
--- a/lxd/containers_get.go
+++ b/lxd/containers_get.go
@@ -94,6 +94,7 @@ func doContainersGet(d *Daemon, r *http.Request) (interface{}, error) {
 			for _, container := range containers {
 				resultAppend(container, api.Container{}, fmt.Errorf("unavailable"))
 			}
+
 			continue
 		}
 
@@ -104,17 +105,21 @@ func doContainersGet(d *Daemon, r *http.Request) (interface{}, error) {
 			go func(address string, containers []string) {
 				defer wg.Done()
 				cert := d.endpoints.NetworkCert()
+
 				cs, err := doContainersGetFromNode(address, cert)
 				if err != nil {
 					for _, name := range containers {
 						resultAppend(name, api.Container{}, err)
 					}
+
 					return
 				}
+
 				for _, c := range cs {
 					resultAppend(c.Name, c, nil)
 				}
 			}(address, containers)
+
 			continue
 		}
 
@@ -126,7 +131,11 @@ func doContainersGet(d *Daemon, r *http.Request) (interface{}, error) {
 			}
 
 			c, err := doContainerGet(d.State(), container)
-			resultAppend(container, *c, err)
+			if err != nil {
+				resultAppend(container, api.Container{}, err)
+			} else {
+				resultAppend(container, *c, err)
+			}
 		}
 	}
 	wg.Wait()


More information about the lxc-devel mailing list