WSL: fcntl(F_SETLK) for setting byte range locks is broken leading to data corruption
My WSL is the Creator’s Update 1703. uname -r reports 4.4.0-43-Microsoft
I’m seeing fcntl(F_SETLK) permit multiple exclusive locks on WSL which is bad, it’s instant data corruption for anything relying on this to work. This test launches four child processes and uses a shared memory map to check if fcntl(F_SETLK) is working correctly. This test passes on real Linux, fails badly on WSL:
integration/afio/shared_fs_mutex_byte_ranges/exclusives:
Tests that afio::algorithm::shared_fs_mutex::byte_ranges implementation implements exclusive locking
CHECK ((i.results[0] == 'o' && i.results[1] == 'k')) FAILED at /home/ned/windocs/boostish/afio/test/tests/shared_fs_mutex.cpp:283
Child reports Child 0 released exclusive lock to find child 3 had stolen my lock!
CHECK ((i.results[0] == 'o' && i.results[1] == 'k')) FAILED at /home/ned/windocs/boostish/afio/test/tests/shared_fs_mutex.cpp:283
Child reports Child 1 granted exclusive lock when child 2 already has exclusive lock!
CHECK ((i.results[0] == 'o' && i.results[1] == 'k')) FAILED at /home/ned/windocs/boostish/afio/test/tests/shared_fs_mutex.cpp:283
Child reports Child 2 released exclusive lock to find child 1 had stolen my lock!
CHECK ((i.results[0] == 'o' && i.results[1] == 'k')) FAILED at /home/ned/windocs/boostish/afio/test/tests/shared_fs_mutex.cpp:283
Child reports Child 3 granted exclusive lock when child 0 already has exclusive lock!
4 checks passed 4 checks failed duration 5150 ms
While you’re at it, if you could implement the non-insane fcntl(F_OFD_SETLK) locks that would be very useful. The fcntl(F_SETLK) type locks are stupid.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 24
- Comments: 18
Commits related to this issue
- Workaround for completely broken file locking on Windows 10 WSL. WSL (Windows Services for Linux) provides a Linux-kernel-compatible ABI for userspace processes, but the current version doesn't not i... — committed to apenwarr/redo by apenwarr 8 years ago
- don't use flock on wsl -- it's broken there touch /tmp/lock zmodload zsh/system zsystem flock /tmp/lock ( zsystem flock /tmp/lock ) # must hang but on wsl it doesn't See: - https:/... — committed to romkatv/gitstatus by romkatv 7 years ago
- don't use flock on wsl -- it's broken there touch /tmp/lock zmodload zsh/system zsystem flock /tmp/lock ( zsystem flock /tmp/lock ) # must hang but on wsl it doesn't See: - https:/... — committed to romkatv/gitstatus by romkatv 7 years ago
- Squashed commit of the following: commit 03f052671a8de9f77715d1c457588964a4b07fb7 Author: William Hay <wish@dumain.com> Date: Sat Nov 9 14:41:34 2024 +0000 Remove .pylintrc commit 235ca1bcf7b... — committed to dumain/minimal-do by dumain 2 years ago
Why will this not be fixed in WSL-1. The WSL-2 environment cannot be used on older CPU-environments and WSL-1 is unusable for me when this is not fixed. Why does Microsoft not fix a bug in a product it still distributes on the newest Windows versions? WSL-2 is not a replacement for WSL-1, says Microsoft. They can be used as different products. This is really terrible, as it is a simple bug that exists already for years.
Still seeing this on Version 1803 (4.4.0-17134-Microsoft).
Are there plans to fix this?
I’m in the same situation as @gertvanantwerpentno I do not want to move to WSL-2 for various reasons and without this being fixed in WSL-1 I’m basically stuck.
Another victim of this issue here,
ubuntu-24.04andapt upgrade. (In my case, I’m using WSL1 because a stupid corporate VPN breaks my networking with WSL2.)Not very elegant, but my workaround was to momentarily convert to WSL2 using (surprisingly, it’s not much time):
, then let apt fix the problem with:
, then convert back to WSL1, with:
It works now (I guess until the next
polkitdupdate…)It is really unlucky that this bug will not get fixed. 😦 WSL 1 is not obsolete, for example on GitHub Actions WSL 2 is simply technically not possible, so there you can only use WSL 1. And currently if you for example use
kali-linuxand try to installsudoit fails due to this bug. Or if you try to useubuntu-24.04and do anapt update, it also fails due to this bug. :‘’'-(Me too, @StephenAtty .
The issue referenced looks like lock files, not byte range locks. Another test in my test suite tests lock files and it passes on WSL. Still, the issues could be related.
It should be trivially easy to convert the new ORD locks to LockFileEx. The older POSIX locks would require a little more work to emulate the broken semantics required by POSIX. In any case they should return ENOTSUPP or something so implementations can choose a backup locking system like lock files.