authorgravatar for andrius.bentkus@gmail.comAndrius Bentkus <andrius.bentkus@gmail.com> 2022-07-16 15:46:13+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-11 06:20:51-05:00
log4ea2f441df36cec61e1017f4d795d4037326c98c
tree3d81e5fd8e13902cafc54843c0c5c080528ec681
parent3169f0529b22fca2a387a841a62fec29b3d2096a

Module: retry ZIR cache file creation

There are no dir components, so you would think that this was unreachable, however we have observed on macOS two processes racing to do openat() with O_CREAT manifest in ENOENT. closes #12138

1 files changed, 19 insertions(+), 14 deletions(-)

src/Module.zig+19-14
......@@ -3569,20 +3569,25 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
35693569 // If another process is already working on this file, we will get the cached
35703570 // version. Likewise if we're working on AstGen and another process asks for
35713571 // the cached file, they'll get it.
3572 const cache_file = zir_dir.createFile(&digest, .{
3573 .read = true,
3574 .truncate = false,
3575 .lock = lock,
3576 }) catch |err| switch (err) {
3577 error.NotDir => unreachable, // no dir components
3578 error.InvalidUtf8 => unreachable, // it's a hex encoded name
3579 error.BadPathName => unreachable, // it's a hex encoded name
3580 error.NameTooLong => unreachable, // it's a fixed size name
3581 error.PipeBusy => unreachable, // it's not a pipe
3582 error.WouldBlock => unreachable, // not asking for non-blocking I/O
3583 error.FileNotFound => unreachable, // no dir components
3584
3585 else => |e| return e, // Retryable errors are handled at callsite.
3572 const cache_file = while (true) {
3573 break zir_dir.createFile(&digest, .{
3574 .read = true,
3575 .truncate = false,
3576 .lock = lock,
3577 }) catch |err| switch (err) {
3578 error.NotDir => unreachable, // no dir components
3579 error.InvalidUtf8 => unreachable, // it's a hex encoded name
3580 error.BadPathName => unreachable, // it's a hex encoded name
3581 error.NameTooLong => unreachable, // it's a fixed size name
3582 error.PipeBusy => unreachable, // it's not a pipe
3583 error.WouldBlock => unreachable, // not asking for non-blocking I/O
3584 // There are no dir components, so you would think that this was
3585 // unreachable, however we have observed on macOS two processes racing
3586 // to do openat() with O_CREAT manifest in ENOENT.
3587 error.FileNotFound => continue,
3588
3589 else => |e| return e, // Retryable errors are handled at callsite.
3590 };
35863591 };
35873592 defer cache_file.close();
35883593