[lxc-devel] [lxd/master] lxd/backup: Fixes hang in backupCreate when invalid compressio argument supplied

tomponline on Github lxc-bot at linuxcontainers.org
Thu May 28 08:23:18 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 431 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200528/818f570c/attachment.bin>
-------------- next part --------------
From e9c2af05669efd219e45d30676f2867dd2a65828 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 28 May 2020 09:21:55 +0100
Subject: [PATCH] lxd/backup: Fixes hang in backupCreate when invalid
 compressio argument supplied

Similar to 5ac84466558c0f48207f0f15807209c758fbf713

Fixes #7455

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/backup.go | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lxd/backup.go b/lxd/backup.go
index 2e0385964c..a938311e14 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -121,11 +121,18 @@ func backupCreate(s *state.State, args db.InstanceBackup, sourceInst instance.In
 
 	// Setup tar writer go routine, with optional compression.
 	tarWriterRes := make(chan error, 0)
+	var compressErr error
+
 	go func(resCh chan<- error) {
 		logger.Debug("Started backup tarball writer")
 		defer logger.Debug("Finished backup tarball writer")
 		if compress != "none" {
-			err = compressFile(compress, tarPipeReader, tarFileWriter)
+			compressErr = compressFile(compress, tarPipeReader, tarFileWriter)
+
+			// If a compression error occurred, close the tarPipeWriter to end the export.
+			if compressErr != nil {
+				tarPipeWriter.Close()
+			}
 		} else {
 			_, err = io.Copy(tarFileWriter, tarPipeReader)
 		}
@@ -135,6 +142,13 @@ func backupCreate(s *state.State, args db.InstanceBackup, sourceInst instance.In
 	// Write index file.
 	logger.Debug("Adding backup index file")
 	err = backupWriteIndex(sourceInst, pool, b.OptimizedStorage(), !b.InstanceOnly(), tarWriter)
+
+	// Check compression errors.
+	if compressErr != nil {
+		return compressErr
+	}
+
+	// Check backupWriteIndex for errors.
 	if err != nil {
 		return errors.Wrapf(err, "Error writing backup index file")
 	}


More information about the lxc-devel mailing list