From 0db7eadccdb926e2c2aa952e66a2d46d29c3bbe9 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Fri, 11 Sep 2026 23:11:08 -0700 Subject: [PATCH] Compilation: close the linker output file before writing whole cache manifest The issue that this fixes was previously fixed in 5e0e1841c0, but regressed in 77a4c4bbcf. This is something of a combination of both changes: - `comp.bin_file` remains non-null so the defer can run to update the progress node - Closing the file and releasing the lock has been re-introduced, which is the important bit of the `destroy()` call that was removed in 77a4c4bbcf Closes https://codeberg.org/ziglang/zig/issues/36651 --- src/Compilation.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Compilation.zig b/src/Compilation.zig index 711b434c57d85cd9f6ae6df784f4b73a529b4b1e..d1a95dd5f2ac14df15161547b5d3f1351bd10a8e 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3151,6 +3151,17 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE // cache manifest must not be written. if (anyErrors(comp)) return; + // Release the lock and close the file before writing the manifest. + // This avoids the potential of another process getting a cache hit and + // trying to spawn a process with it while there's still an open fd to it. + if (comp.bin_file) |lf| { + lf.releaseLock(); + if (lf.file) |f| { + f.close(io); + lf.file = null; + } + } + // Failure here only means an unnecessary cache miss. man.writeManifest() catch |err| log.warn("failed to write cache manifest: {t}", .{err}); -- 2.54.0