From 6aa14724311770edc829a0b1169b1f41c2841246 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Mon, 26 Oct 2026 08:48:12 +0000 Subject: [PATCH] testfile: retry Remove on transient Windows sharing violations On Windows CI, os.Remove on a file that was just written can fail with "The process cannot access the file because it is being used by another process" while another process still holds it open. This failed TestSyncIncrementalFileOverwritesFolder (azure windows, 2026-10-25) and the subsequent waitForCompletionMarker then timed out. Retry the removal for a bounded time so the test does not depend on that handle being released immediately. Co-authored-by: Isaac --- libs/testfile/testfile.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libs/testfile/testfile.go b/libs/testfile/testfile.go index c3b29f38d39..4de3a81245c 100644 --- a/libs/testfile/testfile.go +++ b/libs/testfile/testfile.go @@ -59,6 +59,16 @@ func (f *TestFile) Overwrite(t *testing.T, s string) { func (f *TestFile) Remove(t *testing.T) { f.Close(t) - err := os.Remove(f.path) - assert.NoError(t, err) + // On Windows, a file that was just written can be briefly held open by another + // process (e.g. antivirus or the search indexer), so remove fails with a sharing + // violation. Retry for a bounded time before failing. + deadline := time.Now().Add(10 * time.Second) + for { + err := os.Remove(f.path) + if err == nil || time.Now().After(deadline) { + assert.NoError(t, err) + return + } + time.Sleep(100 * time.Millisecond) + } }