authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-25 03:45:10+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-25 19:33:43+01:00
log5e0e1841c060ea823d8869b8408e18eec52cba71
treeb09d550598690d166e5848e09c143527c68fae68
parent8a517285cebb007f14d499c611f3a052f45f0683

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

1 files changed, 5 insertions(+), 5 deletions(-)

src/Compilation.zig+5-5
......@@ -3230,16 +3230,16 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
32303230 // cache manifest must not be written.
32313231 if (anyErrors(comp)) return;
32323232
3233 // Failure here only means an unnecessary cache miss.
3234 man.writeManifest() catch |err| {
3235 log.warn("failed to write cache manifest: {s}", .{@errorName(err)});
3236 };
3237
32383233 if (comp.bin_file) |lf| {
32393234 lf.destroy();
32403235 comp.bin_file = null;
32413236 }
32423237
3238 // Failure here only means an unnecessary cache miss.
3239 man.writeManifest() catch |err| {
3240 log.warn("failed to write cache manifest: {s}", .{@errorName(err)});
3241 };
3242
32433243 assert(whole.lock == null);
32443244 whole.lock = man.toOwnedLock();
32453245 },