can't reliably stat() some files using relative paths

Originator:thakis
Number:rdar://FB8957317 Date Originated:2020 Dec 30
Status: Resolved:
Product:macos Product Version:11.0.1
Classification:bug Reproducible:yes
 
The following program tries to stat() /usr/bin/env using a relative path from the user's home directory. (This means it crosses an APFS container boundary, which might be relevant). Every now and then (in this example, once after a little over 8 million tries), the stat fails with ENOENT. This is a problem for build systems that stat files to see if they exist and/or out of date. This is a regression in catalina. We've seen this on our build bots.

% pwd
/Users/thakis

% cat a.c
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

int main() {
  for (int count = 0; ; ++count) {
    struct stat st;
    if (stat("../../usr/bin/env", &st) < 0) {
      if (errno == ENOENT)
        fprintf(stderr, "got ENOENT, count=%d\n", count);
      return 1;
    }
  }
}
% clang a.c -O2
% time ./a.out
got ENOENT, count=8335512
./a.out  0.50s user 10.92s system 78% cpu 14.536 total

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!