From 8a486eafed6b2a2304d4d4708cb00a225f48bb26 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 30 Jan 2021 00:39:32 +0100 Subject: [PATCH] gs: Don't drop error when finishing upload The error returned when finishing the upload of an object was dropped. This could cause silent upload failures and thus data loss in certain cases. When a MD5 hash for the uploaded blob is specified, a wrong hash/damaged upload would return its error via the Close() whose error was dropped. --- changelog/unreleased/pull-3249 | 7 +++++++ internal/backend/gs/gs.go | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/pull-3249 diff --git a/changelog/unreleased/pull-3249 b/changelog/unreleased/pull-3249 new file mode 100644 index 000000000..696cba521 --- /dev/null +++ b/changelog/unreleased/pull-3249 @@ -0,0 +1,7 @@ +Bugfix: Better error handling for gs backend + +The gs backend did not notice when the last steep of completing a file upload +failed. Under rare circumstance, this might be able to cause missing files in +the backup repository. This has been fixed. + +https://github.com/restic/restic/pull/3249 diff --git a/internal/backend/gs/gs.go b/internal/backend/gs/gs.go index 7e4ac0702..70af32d25 100644 --- a/internal/backend/gs/gs.go +++ b/internal/backend/gs/gs.go @@ -235,7 +235,10 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe w := be.bucket.Object(objName).NewWriter(ctx) w.ChunkSize = 0 wbytes, err := io.Copy(w, rd) - w.Close() + cerr := w.Close() + if err == nil { + err = cerr + } be.sem.ReleaseToken()