Skip to content

Commit d06c911

Browse files
Bryan C. Millscherrymui
Bryan C. Mills
authored andcommitted
[release-branch.go1.18] testing: include ERROR_SHARING_VIOLATION in Windows cleanup retries
Fixes #52986 Updates #51442 Updates #50051 Change-Id: I1bfbc08c907077467fd50febbec6299a9b73af41 Reviewed-on: https://go-review.googlesource.com/c/go/+/388916 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> (cherry picked from commit eeb9f09) Reviewed-on: https://go-review.googlesource.com/c/go/+/407877 Reviewed-by: Nooras Saba‎ <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent d252fdd commit d06c911

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/testing/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ func removeAll(path string) error {
11221122
)
11231123
for {
11241124
err := os.RemoveAll(path)
1125-
if !isWindowsAccessDenied(err) {
1125+
if !isWindowsRetryable(err) {
11261126
return err
11271127
}
11281128
if start.IsZero() {

src/testing/testing_other.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
package testing
88

9-
// isWindowsAccessDenied reports whether err is ERROR_ACCESS_DENIED,
10-
// which is defined only on Windows.
11-
func isWindowsAccessDenied(err error) bool {
9+
// isWindowsRetryable reports whether err is a Windows error code
10+
// that may be fixed by retrying a failed filesystem operation.
11+
func isWindowsRetryable(err error) bool {
1212
return false
1313
}

src/testing/testing_windows.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ package testing
88

99
import (
1010
"errors"
11+
"internal/syscall/windows"
1112
"syscall"
1213
)
1314

14-
// isWindowsAccessDenied reports whether err is ERROR_ACCESS_DENIED,
15-
// which is defined only on Windows.
16-
func isWindowsAccessDenied(err error) bool {
17-
return errors.Is(err, syscall.ERROR_ACCESS_DENIED)
15+
// isWindowsRetryable reports whether err is a Windows error code
16+
// that may be fixed by retrying a failed filesystem operation.
17+
func isWindowsRetryable(err error) bool {
18+
for {
19+
unwrapped := errors.Unwrap(err)
20+
if unwrapped == nil {
21+
break
22+
}
23+
err = unwrapped
24+
}
25+
if err == syscall.ERROR_ACCESS_DENIED {
26+
return true // Observed in https://go.dev/issue/50051.
27+
}
28+
if err == windows.ERROR_SHARING_VIOLATION {
29+
return true // Observed in https://go.dev/issue/51442.
30+
}
31+
return false
1832
}

0 commit comments

Comments
 (0)