From 2579fe6b7bd55f341f333f4d2dab7f3a539652a5 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 30 Nov 2017 21:23:43 +0100 Subject: [PATCH 1/2] Ignore SIGPIPE Handling SIGPIPE made restic abort when a TCP connection was reset by a server. This happened on DigitalOcean Spaces, which uses the s3 backend. --- cmd/restic/cleanup.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index 04875fe45..daa8ec228 100644 --- a/cmd/restic/cleanup.go +++ b/cmd/restic/cleanup.go @@ -25,16 +25,14 @@ func init() { InstallSignalHandler() } -// InstallSignalHandler listens for SIGINT and SIGPIPE, and triggers the cleanup handlers. +// InstallSignalHandler listens for SIGINT, and triggers the cleanup handlers. func InstallSignalHandler() { signal.Notify(cleanupHandlers.ch, syscall.SIGINT) - signal.Notify(cleanupHandlers.ch, syscall.SIGPIPE) } -// SuspendSignalHandler removes the signal handler for SIGINT and SIGPIPE. +// SuspendSignalHandler removes the signal handler for SIGINT. func SuspendSignalHandler() { signal.Reset(syscall.SIGINT) - signal.Reset(syscall.SIGPIPE) } // AddCleanupHandler adds the function f to the list of cleanup handlers so @@ -69,7 +67,7 @@ func RunCleanupHandlers() { cleanupHandlers.list = nil } -// CleanupHandler handles the SIGINT and SIGPIPE signals. +// CleanupHandler handles the SIGINT signals. func CleanupHandler(c <-chan os.Signal) { for s := range c { debug.Log("signal %v received, cleaning up", s) From 0b44c629f2e5ee004ea0c14ff2d6e8744e82f08c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 30 Nov 2017 22:05:14 +0100 Subject: [PATCH 2/2] retry: Remove file after failed save --- internal/backend/backend_retry.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/backend/backend_retry.go b/internal/backend/backend_retry.go index fae70cd9d..1d4c24859 100644 --- a/internal/backend/backend_retry.go +++ b/internal/backend/backend_retry.go @@ -7,6 +7,7 @@ import ( "time" "github.com/cenkalti/backoff" + "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" ) @@ -65,7 +66,19 @@ func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd io.Reader) return err } - return be.Backend.Save(ctx, h, rd) + err = be.Backend.Save(ctx, h, rd) + if err == nil { + return nil + } + + debug.Log("Save(%v) failed with error, removing file: %v", h, err) + rerr := be.Remove(ctx, h) + if rerr != nil { + debug.Log("Remove(%v) returned error: %v", h, err) + } + + // return original error + return err }) }