From 736e964317a9e323a29201f07940dfe8380d193d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 13 Dec 2020 20:01:16 +0100 Subject: [PATCH] archiver: Don't loose error if background context is canceled A canceled background context lets the blob/tree/fileSavers exit without reporting an error. The error handling previously replaced a 'context canceled' error received by the main backup method with the error reported by the savers. However, in case of a canceled background context that error is nil, causing restic to loose the error and save a snapshot with a nil tree. --- internal/archiver/archiver.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index 5573f1722..2e4af5cd8 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -803,7 +803,8 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps t.Kill(nil) werr := t.Wait() debug.Log("err is %v, werr is %v", err, werr) - if err == nil || errors.Cause(err) == context.Canceled { + // Use werr when it might contain a more specific error than "context canceled" + if err == nil || (errors.Cause(err) == context.Canceled && werr != nil) { err = werr }