From fc60b560ba3694d47f21a8bf690eb415e8122847 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 13 Dec 2020 20:06:44 +0100 Subject: [PATCH] archiver: Let saveTree report a canceled context as an error If the context was canceled then saveTree might receive a treeID or not depending on the timing. This could cause saveTree to incorrectly return a nil treeID as valid. Fix this always returning an error when the context was canceled in the meantime. --- internal/archiver/archiver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index 2e4af5cd8..4992d439b 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -178,6 +178,10 @@ func (arch *Archiver) saveTree(ctx context.Context, t *restic.Tree) (restic.ID, s.TreeBlobs++ s.TreeSize += uint64(len(buf)) } + // The context was canceled in the meantime, res.ID() might be invalid + if ctx.Err() != nil { + return restic.ID{}, s, ctx.Err() + } return res.ID(), s, nil }