Replace cleanup handlers with context based command cancelation#4753
Merged
MichaelEischer merged 10 commits intorestic:masterfrom Apr 24, 2024
Merged
Replace cleanup handlers with context based command cancelation#4753MichaelEischer merged 10 commits intorestic:masterfrom
MichaelEischer merged 10 commits intorestic:masterfrom
Conversation
8169a0f to
0ac5e1a
Compare
move terminal restoration into readPasswordTerminal
This forces a caller to actually check that the function did complete.
0ac5e1a to
484dbb1
Compare
Member
Author
|
LGTM |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR change? What problem does it solve?
Restic has historically relied on a homegrown mechanism using cleanup handlers to handle command interrupts like SIGINT. This PR completely removes that mechanism and only uses
Contexts to cancel commands. This removes another source of global state fromcmd/restic/and might be useful in the future as it allows for a controlled shutdown of commands compared to the current approach that is more akin to a "controlled crash".Due to the cleanup handlers approach there was no need to ensure that every command exits as fast as possible once a context has been canceled. This PR therefore adds lots of checks for canceled contexts. Previously, if the cleanup handlers took too long, then a command like prune could in some cases erroneously report a corrupted repository.
From a user perspective there shouldn't be any large changes, although the text output of an interrupted command will change slightly.
There are two ugly parts in the current implementation: reading a password and serving a fuse mount appear to offer no nice way to honor a canceled context. To still somewhat integrate with context cancellation, the blocking command runs in a separate goroutine that is leaked if the command gets canceled. This is good enough for uses in restic, as canceling the context will result in program termination anyways.
Was the change previously discussed in an issue or on the forum?
Mentioned as part of the restic 0.17.0 roadmap. Prerequisite for #4406 .
Checklist
[ ] I have added documentation for relevant changes (in the manual).[ ] There's a new file inchangelog/unreleased/that describes the changes for our users (see template).gofmton the code in all commits.