Skip to content

Catch SIGTERM, run cleanup#4703

Merged
MichaelEischer merged 3 commits intorestic:masterfrom
ferringb:master
Feb 22, 2024
Merged

Catch SIGTERM, run cleanup#4703
MichaelEischer merged 3 commits intorestic:masterfrom
ferringb:master

Conversation

@ferringb
Copy link
Copy Markdown
Contributor

@ferringb ferringb commented Feb 19, 2024

The previous code only ran cleanup (lock release for example) on SIGINT. For anyone running restic in a container, the signal is going to be SIGTERM which means containerized execution would leave locks behind.

While this could be addressed via interposing dumb-init to translate the signal, a kill invocation is going to default to SIGTERM, so the same problem exists for non container users.

What does this PR change? What problem does it solve?

This change ensures restic shuts down cleanly when SIGTERM'd. It currently handles SIGINT only.

For the containerized docker image, any stopping of the container results in restic being SIGTERM'd which means it
leaves behind locks and other undesirables. This problem can also exist for CLI invocation of restic- killall restic would accomplish the same.

Was the change previously discussed in an issue or on the forum?

Ish. People talk in the forums of shutting restic down with SIGINT/SIGTERM (https://forum.restic.net/t/robustness-of-repository-issue-resolved/1475/3 for example), but nothing in the codebases history- that I can find- has SIGTERM awareness.

Minimally, manual testing of current restic confirms it lacks SIGTERM handling, so I assume folks were just... assuming...

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes. (no tests pre-exist for SIGINT)
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I have run gofmt on the code in all commits.
  • All commit messages are formatted in the same style as the other commits in the repo.
  • I'm done! This pull request is ready for review.

The previous code only ran cleanup (lock release for example) on SIGINT.  For
anyone running restic in a container, the signal is going to be SIGTERM which
means containerized execution would leave locks behind.

While this could be addressed via interposing dumb-init to translate the signal,
a `kill` invocation is going to default to SIGTERM, so the same problem exists
for non container users.

Signed-off-by: Brian Harring <ferringb@gmail.com>
Signed-off-by: Brian Harring <ferringb@gmail.com>
@ferringb
Copy link
Copy Markdown
Contributor Author

A point of discussion here is what to do with the env var RESTIC_DEBUG_STACKTRACE_SIGINT; while that's clearly for debugging, the name has 'SIGINT' in it; it my be desirable to rename that to reflect it's a debug dump for any cleanup.

That said, it's clearly something of an internal/debugging feature, so it likely can be ignored?

@ferringb ferringb marked this pull request as ready for review February 19, 2024 10:44
@ferringb
Copy link
Copy Markdown
Contributor Author

Also, #1064 (comment) implies SIGTERM was tested/validated; I cannot repro that (at least not for restic backup).

Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Let's keep RESTIC_DEBUG_STACKTRACE_SIGINT as it is. It is primarily intended for Windows, and there only SIGINT exists. Only Unix system one would just send SIGQUIT to restic to achieve the same effect in a far more comfortable way.

@MichaelEischer MichaelEischer added this pull request to the merge queue Feb 22, 2024
Merged via the queue into restic:master with commit c6311c1 Feb 22, 2024
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.

2 participants