commit 5e0e1841c060ea823d8869b8408e18eec52cba71 (tree)
parent 8a517285cebb007f14d499c611f3a052f45f0683
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Wed, 25 Mar 2026 03:45:10 +0100
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
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git 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();
},