From 5e0e1841c060ea823d8869b8408e18eec52cba71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 25 Mar 2026 03:45:10 +0100 Subject: [PATCH] Compilation: close the linker output file before writing whole cache manifest Otherwise a different process may get a cache hit on the file while we still have a writable fd open for it. This isn't actually a real problem in the sense that running the file should just work as expected if the OS allows it. But until very recently[0], the Linux kernel would give ETXTBSY in this case. So make sure we close the file before letting other processes know that it's usable. closes https://codeberg.org/ziglang/zig/issues/31563 [0] https://github.com/torvalds/linux/commit/2a010c41285345da60cece35575b4e0af7e7bf44 --- src/Compilation.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 8cc930b037..a82cf46fd8 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3230,16 +3230,16 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE // cache manifest must not be written. if (anyErrors(comp)) return; - // Failure here only means an unnecessary cache miss. - man.writeManifest() catch |err| { - log.warn("failed to write cache manifest: {s}", .{@errorName(err)}); - }; - if (comp.bin_file) |lf| { lf.destroy(); comp.bin_file = null; } + // Failure here only means an unnecessary cache miss. + man.writeManifest() catch |err| { + log.warn("failed to write cache manifest: {s}", .{@errorName(err)}); + }; + assert(whole.lock == null); whole.lock = man.toOwnedLock(); },