diff mbox series

[wrynose,2.18,2/2] utils: Add NFS EEXISTS/isdir failure workaround

Message ID fae9db3168dbff1b8c76fe9c6726a9687ff97514.1784281828.git.yoann.congal@smile.fr
State New
Headers show
Series [wrynose,2.18,1/2] bitbake-setup: always write newline at end of the README | expand

Commit Message

Yoann Congal July 17, 2026, 9:52 a.m. UTC
From: Richard Purdie <richard.purdie@linuxfoundation.org>

We're seeing cases where we see tracebacks when creating directories in
SSTATE_DIR on an NFS server. The issue is that we see EEXISTS being returned
but isdir() is False, likely when multiple clients try and create the same
directory at the same time.

This is likely a relatively well known issue with NFS's attribute cache.
There is also a way to clear the attribute cache, which is to call
opendir() on the parent directory. That is what this workaround does. In
the rare case we're about to fail, try that using os.listdir() and
see if it helps. Testing showed that it would "fix" several cases
where we'd have had failures otherwise.

[YOCTO #16351]

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 3a99c26fa581d70ed67bd08a5e0e0d0b18369a7c)
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 lib/bb/utils.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index b04ff6ffc..a91bebf5f 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -944,8 +944,20 @@  def mkdirhier(directory):
     try:
         os.makedirs(directory)
     except OSError as e:
-        if e.errno != errno.EEXIST or not os.path.isdir(directory):
+        if e.errno != errno.EEXIST:
             raise e
+        if os.path.isdir(directory):
+            return
+        # We can end up here if there is a race between two mkdirs on an NFS mount,
+        # which happens more often with sstate that you'd think. The server returns
+        # EEXIST but the local attribute cache is out of date. It can be refreshed with
+        # an opendir call, so try that (via listdir) and check the directory again
+        # before we really fail.
+        os.listdir(os.path.dirname(directory))
+        if os.path.isdir(directory):
+            return
+        bb.warn("mkdir: %s is not a directory?")
+        raise e
 
 def movefile(src, dest, newmtime = None, sstat = None):
     """Moves a file from ``src`` to ``dest``, preserving all permissions and