From 1220fe96505bcd117efa840ad1c82fe39e87d5a7 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Sat, 17 Sep 2022 19:37:09 +0200 Subject: [PATCH 1/2] internal/cache: Concurrent use of cache not working on Windows --- internal/cache/file_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/cache/file_test.go b/internal/cache/file_test.go index 388d7d4f7..87664f014 100644 --- a/internal/cache/file_test.go +++ b/internal/cache/file_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "math/rand" "os" + "runtime" "testing" "time" @@ -204,7 +205,19 @@ func TestFileLoad(t *testing.T) { } // Simulate multiple processes writing to a cache, using goroutines. +// +// The possibility of sharing a cache between multiple concurrent restic +// processes isn't guaranteed in the docs and doesn't always work on Windows +// due to the Go runtime opening files without FILE_SHARE_DELETE, hence the +// check on GOOS. This is considered a "nice to have" on POSIX, for now. +// +// See https://devblogs.microsoft.com/oldnewthing/20211022-00/?p=105822 +// for hints on how to fix this properly. func TestFileSaveConcurrent(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("may not work due to FILE_SHARE_DELETE issue") + } + const nproc = 40 c, cleanup := TestNewCache(t) From 7fc178aaf48453f42c0ce33663c2f14a56f5a7e1 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 24 Sep 2022 13:07:01 +0200 Subject: [PATCH 2/2] internal/cache: extend description of cache sharing test failure --- internal/cache/file_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/cache/file_test.go b/internal/cache/file_test.go index 87664f014..3e92c1d96 100644 --- a/internal/cache/file_test.go +++ b/internal/cache/file_test.go @@ -207,10 +207,13 @@ func TestFileLoad(t *testing.T) { // Simulate multiple processes writing to a cache, using goroutines. // // The possibility of sharing a cache between multiple concurrent restic -// processes isn't guaranteed in the docs and doesn't always work on Windows -// due to the Go runtime opening files without FILE_SHARE_DELETE, hence the -// check on GOOS. This is considered a "nice to have" on POSIX, for now. +// processes isn't guaranteed in the docs and doesn't always work on Windows, hence the +// check on GOOS. Cache sharing is considered a "nice to have" on POSIX, for now. // +// The cache first creates a temporary file and then renames it to its final name. +// On Windows renaming internally creates a file handle with a shareMode which +// includes FILE_SHARE_DELETE. The Go runtime opens files without FILE_SHARE_DELETE, +// thus Open(fn) will fail until the file handle used for renaming was closed. // See https://devblogs.microsoft.com/oldnewthing/20211022-00/?p=105822 // for hints on how to fix this properly. func TestFileSaveConcurrent(t *testing.T) {