Skip to content

Fix rclone backend not properly handling subprocess exit#2797

Closed
greatroar wants to merge 2 commits intorestic:masterfrom
greatroar:rclone-exit
Closed

Fix rclone backend not properly handling subprocess exit#2797
greatroar wants to merge 2 commits intorestic:masterfrom
greatroar:rclone-exit

Conversation

@greatroar
Copy link
Copy Markdown
Contributor

@greatroar greatroar commented Jun 18, 2020

What is the purpose of this change? What does it change?

When rclone exits unexpectedly, restic can hang. The problem occurs in the REST backend, which does not detect that its connection over stdin/stdout has stopped working.

This patch is a (hacky) fix for that problem: it simply closes stdin and stdout when the process is gone. Why this doesn't produce a SIGPIPE is beyond me. The error message is ugly, but at least it arrives instantly.

I have some ideas about how to fix this properly, but they may require quite a bit of code (if they even turn out correct). I suggest merging this as a hotfix.

I was hoping to fix the flaky rclone test, but I don't think this patch does that.

Was the change discussed in an issue or in the forum before?

Fixes #2381.

Checklist

This forces an error in the REST backend, which otherwise would hang
indefinitely.

Fixes restic#2381.
@MichaelEischer
Copy link
Copy Markdown
Member

Why this doesn't produce a SIGPIPE is beyond me.

The default behavior of Go is to trigger SIGPIPE for stdout and stderr and to convert the signal into an EPIPE error for all other file descriptors.

The root cause for restic not noticing the subprocess exit is that restic currently holds on to file descriptors for both the read and write side of the stdin and stdout pipes. That prevents the pipes from closing properly. Calling stdioConn.Close() once the child process has exited is still necessary to free the file descriptors.

I've built a different version of this PR (including your test case) which properly fixes the pipe setup and hopefully also the rclone test failures: #2855

@greatroar
Copy link
Copy Markdown
Contributor Author

Closing in favor of #2855.

@greatroar greatroar closed this Jul 25, 2020
@greatroar greatroar deleted the rclone-exit branch July 25, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restic does not detect rclone termination

2 participants