Skip to content

Remove usage of tomb package#3785

Merged
MichaelEischer merged 3 commits intorestic:masterfrom
MichaelEischer:replace-tomb-usage
Jun 19, 2022
Merged

Remove usage of tomb package#3785
MichaelEischer merged 3 commits intorestic:masterfrom
MichaelEischer:replace-tomb-usage

Conversation

@MichaelEischer
Copy link
Copy Markdown
Member

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

The tomb package is only used within the backup command / the archiver. All other code parts are using errgroup.Group instead. This PR replaces all tomb usages with errgroup to cleanup the code.

tomb offers the t.Kill(nil) method which has no direct equivalence in errgroup. As replacement is is possible to either add explicit methods to shut down tasks as is now done in the archiver.Blob/File/TreeSaver. Or it can be emulated using a combination of errgroup and context.WithCancel:

wg, wgCtx := errgroup.WithContext(ctx)
cancelCtx, cancel := context.WithCancel(wgCtx)
// run workers using cancelCtx
cancel() // replaces t.Kill(nil)

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

No.

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes.
  • [ ] 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.

@greatroar
Copy link
Copy Markdown
Contributor

Nice work. I had two serious tries at this myself, but never ended up with working code that I could submit as a PR.

@MichaelEischer MichaelEischer merged commit bc96879 into restic:master Jun 19, 2022
@MichaelEischer MichaelEischer deleted the replace-tomb-usage branch June 19, 2022 12: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.

2 participants