The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7272

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Fixes #7259

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 5ac84466558c0f48207f0f15807209c758fbf713 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 28 Apr 2020 16:56:59 +0100
Subject: [PATCH] lxd/images: Fixes hang in export when invalid --compression
 argument passed

Fixes #7259

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/images.go | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index c95f9752cd..c4b43d4be6 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -267,25 +267,36 @@ func imgPostContInfo(d *Daemon, r *http.Request, req 
api.ImagesPost, op *operati
                go func() {
                        defer wg.Done()
                        compressErr = compressFile(compress, tarReader, 
compressWriter)
+
+                       // If a compression error occurred, close the writer to 
end the instance export.
+                       if compressErr != nil {
+                               imageProgressWriter.Close()
+                       }
                }()
        } else {
                imageProgressWriter.WriteCloser = imageFile
                writer = io.MultiWriter(imageProgressWriter, sha256)
        }
 
+       // Export instance to writer.
        err = c.Export(writer, req.Properties)
-       // When compression is used, Close on imageProgressWriter/tarWriter
-       // is required for compressFile/gzip to know it is finished.
-       // Otherwise It is equivalent to imageFile.Close.
+
+       // Clean up file handles.
+       // When compression is used, Close on imageProgressWriter/tarWriter is 
required for compressFile/gzip to
+       // know it is finished. Otherwise it is equivalent to imageFile.Close.
        imageProgressWriter.Close()
-       wg.Wait()
-       if err != nil {
-               return nil, err
-       }
+       wg.Wait() // Wait until compression helper has finished if used.
+       imageFile.Close()
+
+       // Check compression errors.
        if compressErr != nil {
                return nil, compressErr
        }
-       imageFile.Close()
+
+       // Check instance export errors.
+       if err != nil {
+               return nil, err
+       }
 
        fi, err := os.Stat(imageFile.Name())
        if err != nil {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to