{"record":{"id":"77ea1719e7542f96","repo":"python/cpython","slug":"cannot-fstat-s","errorCode":null,"errorMessage":"cannot fstat '%s'\n","messagePattern":"cannot fstat '(.+?)'\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Programs/_freeze_module.c","lineNumber":96,"sourceCode":"        (void)PyInitConfig_GetError(config, &err_msg);\n        printf(\"Python init error: %s\\n\", err_msg);\n        PyInitConfig_Free(config);\n        exit(1);\n    }\n}\n\nstatic const char *\nread_text(const char *inpath)\n{\n    FILE *infile = fopen(inpath, \"rb\");\n    if (infile == NULL) {\n        fprintf(stderr, \"cannot open '%s' for reading\\n\", inpath);\n        return NULL;\n    }\n\n    struct _Py_stat_struct stat;\n    if (_Py_fstat_noraise(fileno(infile), &stat)) {\n        fprintf(stderr, \"cannot fstat '%s'\\n\", inpath);\n        fclose(infile);\n        return NULL;\n    }\n    size_t text_size = (size_t)stat.st_size;\n\n    char *text = (char *) malloc(text_size + 1);\n    if (text == NULL) {\n        fprintf(stderr, \"could not allocate %ld bytes\\n\", (long) text_size);\n        fclose(infile);\n        return NULL;\n    }\n    size_t n = fread(text, 1, text_size, infile);\n    fclose(infile);\n\n    if (n < text_size) {\n        fprintf(stderr, \"read too short: got %ld instead of %ld bytes\\n\",\n                (long) n, (long) text_size);\n        free(text);","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Programs/_freeze_module.c#L78-L114","documentation":"Build-time error from Programs/_freeze_module.c: the input file opened successfully, but _Py_fstat_noraise() on its fd failed, so the freezer cannot learn the file size to allocate a buffer. The stream is closed and the freeze step aborts.","triggerScenarios":"The file at inpath is deleted or replaced between fopen() and fstat(); passing a path that resolves to something non-statable (e.g. /proc-like pseudo file on unusual filesystems, or a dangling symlink recreated mid-build); fd exhaustion in parallel builds.","commonSituations":"Concurrent build processes racing over the same generated files; antivirus or filesystem watchers on macOS/Windows transiently blocking stat; building on network filesystems (NFS/SMB) with flaky metadata.","solutions":["Simply rerun the build — transient fstat failures on loaded machines usually clear","Ensure no other job deletes or rewrites the input file during the build (serialize steps that generate it)","Build on a local filesystem instead of NFS/SMB if metadata errors repeat","Check for fd leaks / raise ulimit -n if builds fail at scale"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# shell: ensure inputs are present and stable before the build step\n# [ -f \"$IN\" ] && [ ! -L \"$IN\" ] && stat \"$IN\" >/dev/null || exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate all input files before starting freeze steps (correct dependency order)","Build on local disks, not NFS/SMB, when possible","If failures are sporadic under heavy load, rerun the build before investigating deeper"],"tags":["cpython","build","freeze-module","fstat","filesystem"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}