-
Notifications
You must be signed in to change notification settings - Fork 12.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
Replace fcntl-based file lock with flock #72161
Conversation
WSL1 does not support `fcntl`-based lock and will always report success, therefore creating a race condition when multiple rustc processes are modifying shared data such as `search-index.js`. WSL1 does however support `flock`. `flock` is supported by all unix-like platforms. The only caveat is that Linux 2.6.11 or earlier does not support `flock` on NFS mounts, but as the minimum supported Linux version is 2.6.18, it is not an issue. Fixes rust-lang#72157
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r? @cuviper |
I think this is overstated -- it's a syscall of BSD origin, and my Linux man-page says it appears on most UNIX systems, but in particular it seems Solaris still does not have it.
Since there's nothing really wrong with the current (I know I suggested switching all |
I found that Cargo uses // File locking on Unix is currently implemented via `flock`, which is known
// to be broken on NFS. We could in theory just ignore errors that happen on
// NFS, but apparently the failure mode [1] for `flock` on NFS is **blocking
// forever**, even if the "non-blocking" flag is passed!
//
// As a result, we just skip all file locks entirely on NFS mounts. That
// should avoid calling any `flock` functions at all, and it wouldn't work
// there anyway.
//
// [1]: https://github.com/rust-lang/cargo/issues/2615 They use this for all #[cfg(target_os = "solaris")]
fn flock(file: &File, flag: libc::c_int) -> Result<()> {
// Solaris lacks flock(), so simply succeed with a no-op
Ok(())
} cc @pfmooney who rewrote that recently. |
cc @alexcrichton too, who reviewed that cargo change. |
Much of that locking code was lifted out of fs2, which had become unsuitable due to maintenance concerns (not accepting patches to support new systems/targets). Porting over the A |
Ah indeed. So here is what I originally do to ensure it's okay:
I should probably framed it as "all unix-like platforms" supported by rustc.
Solaris isn't supported by rustc currently. I am not sure if that is a convincing enough reason to not keep the fcntl version?
This is interesting. However Linux man page suggested that on Linux, |
I tested BTW the current approach used in Cargo does affect people as well by not locking on NFS, see rust-lang/cargo#4629. |
FWIW we treat locking as quite optional in Cargo due to it being too restrictive if we require it everywhere. We try to use it everywhere we can but it's empirically had a lot of bugs and had to adjust a lot over time. I doubt Cargo is doing "the best thing" for all platforms under the sun still, and it probably still has issues that need to be worked through. |
@cuviper Is Solaris a platform that rustc ever intends to run on? If so I can bring back |
|
The thing I'm worried about from that comment is the "failure mode" aspect, which I inferred to mean the behavior when the network disappears. But maybe it's also problematic for NFSv3?
I don't know -- it seems the present folks really care about illumos, not solaris proper, which will be getting an independent target as mentioned. My feeling is that we should be really careful about changing this, given the known hazards. We do need to care about it more than Cargo does itself, because |
It's up to the configuration of NFS. If NFS is configured to be uninterruptable and infinite retry, then a network disconnection will cause everything to hang. In that case it does not matter how locks behave, because we will run into issues when doing other IOs as well. Most NFS-related issues are actually poor configuration. If anything can break
We could check if uname contains |
@bors r+ |
📌 Commit a05acbf has been approved by |
Rollup of 4 pull requests Successful merges: - rust-lang#71610 (InvalidUndefBytes: Track size of undef region used) - rust-lang#72161 (Replace fcntl-based file lock with flock) - rust-lang#72306 (Break tokens before checking if they are 'probably equal') - rust-lang#72325 (Always generated object code for `#![no_builtins]`) Failed merges: r? @ghost
WSL1 does not support
fcntl
-based lock and will always report success,therefore creating a race condition when multiple rustc processes are
modifying shared data such as
search-index.js
. WSL1 does howeversupport
flock
.flock
is supported by all unix-like platforms. The only caveat is thatLinux 2.6.11 or earlier does not support
flock
on NFS mounts, but asthe minimum supported Linux version is 2.6.18, it is not an issue.
Fixes #72157