-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inter-process race condition when writing builtin.zig file #14978
Comments
This happens on windows if diff --git a/lib/std/os.zig b/lib/std/os.zig
index 5554e6e31..634c53f6d 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -2697,6 +2697,8 @@ pub fn renameatW(
.FileRenameInformation,
);
+ std.time.sleep(std.time.ns_per_s);
+
switch (rc) {
.SUCCESS => return,
.INVALID_HANDLE => unreachable, const std = @import("std");
pub fn main() !void {
var af = try std.fs.cwd().atomicFile("builtin.zig", .{});
defer af.deinit();
try af.finish();
} |
I think the correct fix is to 1. use Without supporting early Win10 versions, we can get away with the saner option 1. Appendum: Alternative options in the comment section of 2. |
This specific issue is not caused by a lack of atomicity, but rather by an unanticipated (and badly documented) error condition. |
Mhm, that's true. MS docs mentions "If FILE_RENAME_REPLACE_IF_EXISTS is also specified, allow replacing a file even if there are existing handles to it." https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information Not really sure, but the problem could be the same as in DeleteFile without posix semantics, where other process handles must be closed first or worse only in some (error) cases. |
Yes, if you look carefully at where I placed the sleep, it is in between |
Mitigates #14978. Uses the same strategy as in #16499 suggested by @squeek502
This issue already existed in master branch, however, the more aggressive caching of builtin.zig in this branch made it happen more often. I added doc comments to AtomicFile to explain when this problem can occur. For the compiler's use case, error.AccessDenied can be simply swallowed because it means the destination file already exists and there is nothing else to do besides proceed with the AtomicFile cleanup. I never solved the mystery of why the log statements weren't printing but those are temporary debugging instruments anyway, and I am already too many yaks deep to whip out another razor. closes #14978
This issue already existed in master branch, however, the more aggressive caching of builtin.zig in this branch made it happen more often. I added doc comments to AtomicFile to explain when this problem can occur. For the compiler's use case, error.AccessDenied can be simply swallowed because it means the destination file already exists and there is nothing else to do besides proceed with the AtomicFile cleanup. I never solved the mystery of why the log statements weren't printing but those are temporary debugging instruments anyway, and I am already too many yaks deep to whip out another razor. closes #14978
This issue already existed in master branch, however, the more aggressive caching of builtin.zig in this branch made it happen more often. I added doc comments to AtomicFile to explain when this problem can occur. For the compiler's use case, error.AccessDenied can be simply swallowed because it means the destination file already exists and there is nothing else to do besides proceed with the AtomicFile cleanup. I never solved the mystery of why the log statements weren't printing but those are temporary debugging instruments anyway, and I am already too many yaks deep to whip out another razor. closes #14978
This issue already existed in master branch, however, the more aggressive caching of builtin.zig in this branch made it happen more often. I added doc comments to AtomicFile to explain when this problem can occur. For the compiler's use case, error.AccessDenied can be simply swallowed because it means the destination file already exists and there is nothing else to do besides proceed with the AtomicFile cleanup. I never solved the mystery of why the log statements weren't printing but those are temporary debugging instruments anyway, and I am already too many yaks deep to whip out another razor. closes #14978
This issue already existed in master branch, however, the more aggressive caching of builtin.zig in this branch made it happen more often. I added doc comments to AtomicFile to explain when this problem can occur. For the compiler's use case, error.AccessDenied can be simply swallowed because it means the destination file already exists and there is nothing else to do besides proceed with the AtomicFile cleanup. I never solved the mystery of why the log statements weren't printing but those are temporary debugging instruments anyway, and I am already too many yaks deep to whip out another razor. closes #14978
Zig Version
0.11.0-dev.2150+68c7261e1
Steps to Reproduce and Observed Behavior
Expected Behavior
Expected the tests to pass.
The relevant code is here:
zig/src/Module.zig
Lines 3985 to 4015 in 68c7261
The text was updated successfully, but these errors were encountered: