From 0747cf5319775b3deca0ad0db1657e3179f10e06 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 10 Apr 2024 19:17:25 +0200 Subject: [PATCH] cache: ignore ErrNotExist during cleanup of old files Two restic processes running concurrently can try to remove the same files from the cache. This could cause one process to fail with an error if the other one has already remove a file that the current process also tries to delete. --- changelog/unreleased/issue-4760 | 8 ++++++++ internal/cache/file.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/issue-4760 diff --git a/changelog/unreleased/issue-4760 b/changelog/unreleased/issue-4760 new file mode 100644 index 000000000..bb2d9c5b4 --- /dev/null +++ b/changelog/unreleased/issue-4760 @@ -0,0 +1,8 @@ +Bugfix: Fix possible error on concurrent cache cleanup + +If multiple restic processes concurrently cleaned up no longer existing files +from the cache, this could cause some of the processes to fail with an `no such +file or directory` error. This has been fixed. + +https://github.com/restic/restic/issues/4760 +https://github.com/restic/restic/pull/4761 diff --git a/internal/cache/file.go b/internal/cache/file.go index 48a38c1d3..1bfe922d2 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -165,7 +165,8 @@ func (c *Cache) Clear(t restic.FileType, valid restic.IDSet) error { continue } - if err = fs.Remove(c.filename(backend.Handle{Type: t, Name: id.String()})); err != nil { + // ignore ErrNotExist to gracefully handle multiple processes running Clear() concurrently + if err = fs.Remove(c.filename(backend.Handle{Type: t, Name: id.String()})); err != nil && !errors.Is(err, os.ErrNotExist) { return err } }