From: database64128 Date: Thu, 21 Aug 2025 17:03:42 +0000 (+0800) Subject: os: fix Root.MkdirAll to handle race of directory creation X-Git-Tag: go1.26rc1~1037 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a076f49757;p=gostls13.git os: fix Root.MkdirAll to handle race of directory creation No tests were added, because in order to reproduce, the directory would have to be created precisely between the rootOpenDir and mkdirat calls, which is impossible to do in a test. Fixes #75114 Change-Id: I6f86a5b33c87452c35728318eaf2169a7534ef37 Reviewed-on: https://go-review.googlesource.com/c/go/+/698215 LUCI-TryBot-Result: Go LUCI Reviewed-by: Sean Liao Reviewed-by: Damien Neil Reviewed-by: Carlos Amedee Auto-Submit: Sean Liao --- diff --git a/src/os/root_openat.go b/src/os/root_openat.go index e433bd5093..83bde5ef14 100644 --- a/src/os/root_openat.go +++ b/src/os/root_openat.go @@ -131,7 +131,9 @@ func rootMkdirAll(r *Root, fullname string, perm FileMode) error { if try > 0 || !IsNotExist(err) { return 0, &PathError{Op: "openat", Err: err} } - if err := mkdirat(parent, name, perm); err != nil { + // Try again on EEXIST, because the directory may have been created + // by another process or thread between the rootOpenDir and mkdirat calls. + if err := mkdirat(parent, name, perm); err != nil && err != syscall.EEXIST { return 0, &PathError{Op: "mkdirat", Err: err} } }