Open kcbanner opened 2 months ago
cc @jayrod246 (the version in the OP includes https://github.com/ziglang/zig/pull/20907 btw)
I placed this code at line 466 in Watch.zig:
for (files.items) |basename| {
const tmp = try path.joinString(gpa, basename);
defer gpa.free(tmp);
path.access(basename, .{}) catch {
std.debug.print("\n*****************\nFILE MISSING: {s}\n*****************\n", .{tmp});
};
const gop = try reaction_set.getOrPut(gpa, basename);
if (!gop.found_existing) gop.value_ptr.* = .{};
try gop.value_ptr.put(gpa, step, w.generation);
}
and repeating your steps I eventually get:
*****************
FILE MISSING: C:\Dev\watch-test\.zig-cache\o\356a82588c29f2bf10b5221a7f14b907\test.exe
*****************
At this point, the file test.exe
which is an input to some step, gets marked as "persisted". But since that file doesn’t exist, and from what I could tell the parent directory no longer exists either, we get the access denied. I want to guess that the problem stems from somewhere else in the build system? (the input files comes from a Step’s inputs, which are passed in from outside Watch.zig)
This might have more to do with #20631 as I noticed we are attempting to watch directories inside .zig-cache/o/
.
test.exe
is an artifact, which Watch.zig is attempting to track. But the Run step that depends on the artifact should have been invalidated already by the source files from which the artifact is built.
The solution I suppose is to avoid watching artifact directories, which in turn should avoid the AccessDenied error. (which I assume is caused by the Watch.zig file handle we have open on it)
Interesting, yea that does seem to be the cause. Thanks for looking into this!
Zig Version
0.14.0-dev.1077+9be10ea96
Steps to Reproduce and Observed Behavior
zig init
zig build test --watch
src/main.zig
, comment line 24 (so the test fails)Repeat steps 3-5 until the crash is observed - this takes around 3 tries for me (there must be a race condition somewhere in this logic):
Expected Behavior
The watcher should remain alive without crashing.