[lxc-devel] [lxd/master] canceler: Fix goroutine leak on failure
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Oct 28 23:06:59 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201028/849d88cb/attachment.bin>
-------------- next part --------------
From 365d4e97556e10d7997502dbaeb5de78bc4a4d90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 28 Oct 2020 18:48:04 -0400
Subject: [PATCH 1/2] shared/cancel: Close chDone on failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/cancel/canceler.go | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/shared/cancel/canceler.go b/shared/cancel/canceler.go
index b3356cf37e..51263b6020 100644
--- a/shared/cancel/canceler.go
+++ b/shared/cancel/canceler.go
@@ -69,5 +69,10 @@ func CancelableDownload(c *Canceler, client *http.Client, req *http.Request) (*h
}()
resp, err := client.Do(req)
- return resp, chDone, err
+ if err != nil {
+ close(chDone)
+ return nil, nil, err
+ }
+
+ return resp, chDone, nil
}
From 5dbef17cb415de8e3ef5acb3349ae4b77e61ceb9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 28 Oct 2020 18:48:20 -0400
Subject: [PATCH 2/2] lxd: Only close doneCh on success
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/daemon_images.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index 7e272a3a89..3a5b244d7e 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -401,10 +401,10 @@ func (d *Daemon) ImageDownload(op *operations.Operation, server string, protocol
// Make the request
raw, doneCh, err := cancel.CancelableDownload(canceler, httpClient, req)
- defer close(doneCh)
if err != nil {
return nil, err
}
+ defer close(doneCh)
if raw.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Unable to fetch %q: %s", server, raw.Status)
More information about the lxc-devel
mailing list