Skip to content

inter-process race condition when writing builtin.zig file #14978

@andrewrk

Description

@andrewrk

Zig Version

0.11.0-dev.2150+68c7261e1

Steps to Reproduce and Observed Behavior

zig build test
2023-03-17T02:35:33.7612383Z run-translated-c division of floating literals build-exe: error: the following command failed with 1 compilation errors:
2023-03-17T02:35:33.7616740Z C:\actions-runner\_work\zig\zig\build-release\stage3-release\bin\zig.exe build-exe C:\actions-runner\_work\zig\zig\build-release\zig-local-cache\o\c00ed4aa0da85b3d6f53e1b3a4de5d8e\source.zig -lc --cache-dir C:\actions-runner\_work\zig\zig\build-release\zig-local-cache --global-cache-dir C:\actions-runner\_work\zig\zig\build-release\zig-global-cache --name translated_c -L C:\actions-runner\_work\zig\zig\..\zig+llvm+lld+clang-aarch64-windows-gnu-0.11.0-dev.670+f7fea080b\lib -I C:\actions-runner\_work\zig\zig\..\zig+llvm+lld+clang-aarch64-windows-gnu-0.11.0-dev.670+f7fea080b\include --zig-lib-dir C:\actions-runner\_work\zig\zig\lib --enable-cache --listen=- 
2023-03-17T02:41:34.5577258Z Build Summary: 4011/4162 steps succeeded; 147 skipped; 1 failed; 47994/50636 tests passed; 2642 skipped (disable with -fno-summary)
2023-03-17T02:41:34.6550307Z |  +- run-translated-c division of floating literals run transitive failure
2023-03-17T02:41:34.6550500Z |  |  +- run-translated-c division of floating literals build-exe 1 errors
2023-03-17T02:41:34.6550999Z |  |     +- run-translated-c division of floating literals translate-c success 69ms
2023-03-17T02:41:34.6551249Z |  |        +- WriteFile source.c success
2023-03-17T02:41:34.6653922Z error: unable to write builtin.zig to C:\actions-runner\_work\zig\zig\build-release\zig-local-cache\tmp\da8554bcb2aed65d: AccessDenied

Expected Behavior

Expected the tests to pass.

The relevant code is here:

zig/src/Module.zig

Lines 3985 to 4015 in 68c7261

if (builtin_pkg.root_src_directory.handle.statFile(builtin_pkg.root_src_path)) |stat| {
if (stat.size != file.source.len) {
const full_path = try builtin_pkg.root_src_directory.join(gpa, &.{
builtin_pkg.root_src_path,
});
defer gpa.free(full_path);
log.warn(
"the cached file '{s}' had the wrong size. Expected {d}, found {d}. " ++
"Overwriting with correct file contents now",
.{ full_path, file.source.len, stat.size },
);
try writeBuiltinFile(file, builtin_pkg);
} else {
file.stat = .{
.size = stat.size,
.inode = stat.inode,
.mtime = stat.mtime,
};
}
} else |err| switch (err) {
error.BadPathName => unreachable, // it's always "builtin.zig"
error.NameTooLong => unreachable, // it's always "builtin.zig"
error.PipeBusy => unreachable, // it's not a pipe
error.WouldBlock => unreachable, // not asking for non-blocking I/O
error.FileNotFound => try writeBuiltinFile(file, builtin_pkg),
else => |e| return e,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions