From a5b0e0bef4236739ef7906445f8d5dbbf25584ba Mon Sep 17 00:00:00 2001 From: Charlie Jiang Date: Wed, 22 Dec 2021 16:32:23 +0800 Subject: [PATCH] fix: rclone receiving SIGINT prematurely on Windows causing restic hang forever Co-authored-by: greatroar <61184462+greatroar@users.noreply.github.com> --- changelog/unreleased/issue-3601 | 11 +++++++++++ internal/backend/foreground_windows.go | 4 ++++ 2 files changed, 15 insertions(+) create mode 100644 changelog/unreleased/issue-3601 diff --git a/changelog/unreleased/issue-3601 b/changelog/unreleased/issue-3601 new file mode 100644 index 000000000..eb2bf95eb --- /dev/null +++ b/changelog/unreleased/issue-3601 @@ -0,0 +1,11 @@ +Bugfix: Fix rclone backend prematurely exiting when receiving SIGINT on Windows + +On Windows, Restic now start the rclone process detached from the +restic console (similar to starting processes on a new process +group on Linux). Therefore, when Ctrl+C is pressed on the console +where restic runs, restic could gracefully clean up using clone, +and rclone won't exit prematurely leading to restic hanging up with +"stdio pipes closed" errors. + +https://github.com/restic/restic/issue/3601 +https://github.com/restic/restic/pull/3602 \ No newline at end of file diff --git a/internal/backend/foreground_windows.go b/internal/backend/foreground_windows.go index 1c3d1a077..a299f6211 100644 --- a/internal/backend/foreground_windows.go +++ b/internal/backend/foreground_windows.go @@ -2,12 +2,16 @@ package backend import ( "os/exec" + "syscall" "github.com/restic/restic/internal/errors" + "golang.org/x/sys/windows" ) func startForeground(cmd *exec.Cmd) (bg func() error, err error) { // just start the process and hope for the best + cmd.SysProcAttr = &syscall.SysProcAttr{} + cmd.SysProcAttr.CreationFlags = windows.DETACHED_PROCESS err = cmd.Start() if err != nil { return nil, errors.Wrap(err, "cmd.Start")