Prevent lock refresh from leaving behind lots of stale locks#3512
Merged
fd0 merged 3 commits intorestic:masterfrom Mar 21, 2022
Merged
Prevent lock refresh from leaving behind lots of stale locks#3512fd0 merged 3 commits intorestic:masterfrom
fd0 merged 3 commits intorestic:masterfrom
Conversation
tbclark3
approved these changes
Oct 8, 2021
tbclark3
left a comment
There was a problem hiding this comment.
I first noticed the locks problem several weeks ago after running restic for more than a year with no errors. These changes work for me.
This ensures that restic won't create lots of new lock files without deleting them later on. In some cases a Delete operation on a backend can return a "File does not exist" error even though the Delete operation succeeded. This can for example be caused by request retries. This caused restic to forget about the new lock file and continue trying to remove the old (already deleted) lock file.
cleanup handlers run in the order in which they are added. As Go calls init() functions in lexical order, the cleanup handler from global.go was registered before that from lock.go, which is the correct order. Make this order explicit to ensure that this won't break accidentally.
cda7e42 to
aebd24e
Compare
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?
When the lock refresh failed to delete the old lock file, it forgot about the new one. Instead it continued trying to delete the old (usually no longer existing) lock file and thus over time lots of lock files accumulate.
One way to trigger this is when a delete operation seems to fail for example due to a timeout although it actually succeeded.
The PR also contains a small initialization cleanup to ensure that the lock cleanup handler is called after the global context was canceled on interruptions.
Was the change previously discussed in an issue or on the forum?
Fixes #2473
Fixes #2452
Fixes #2562
Checklist
[ ] I have added documentation for relevant changes (in the manual).changelog/unreleased/that describes the changes for our users (see template).gofmton the code in all commits.