Skip to content
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

Support LockFileEx syscall in \\wsl$ directory #5762

Open
kamijin-fanta opened this issue Aug 15, 2020 · 7 comments
Open

Support LockFileEx syscall in \\wsl$ directory #5762

kamijin-fanta opened this issue Aug 15, 2020 · 7 comments
Labels

Comments

@kamijin-fanta
Copy link

Is your feature request related to a problem? Please describe.

Package management tools such as Go Modules and Rust Cargo use Write/Read Lock of File System. This is an important mechanism for removing conflicts.

The WSL2 shared directory \\wsl$ does not seem to support LockFileEx syscall. I confirmed that smb supports it. It returns an Incorrect function. error with the LOCKFILE_EXCLUSIVE_LOCK flag both set/unset.

To solve this problem, Rust Cargo has added code that ignores lock errors. rust-lang/cargo#7602
Go Modules does not work with WSL and officially replied to Issue that WSL is not supported. golang/go#37461

Describe the solution you'd like
Add locking functionality to the shared file system for a better development experience.

Describe alternatives you've considered

  • Added logic to ignore lock errors in package management tools.
  • Launch samba server on WSL2.

Additional context

Below is an example of an error with go modules in latest version.

> go mod download # go version 1.14
go: RLock Z:\example\go.mod: Incorrect function.

simple test code to call LockFileEx

package main

import (
	"os"
	"fmt"
	"golang.org/x/sys/windows"
)

const (
	reserved = 0
	allBytes = ^uint32(0)
)

func main () {
	f, err := os.Open("tmp.txt")
	if err != nil {
		panic(err)
	}
	
	lockType := uint32(2) // 0: readlock 2: writelock
	ol := new(windows.Overlapped)
	err = windows.LockFileEx(windows.Handle(f.Fd()), lockType, reserved, allBytes, allBytes, ol)
	if err != nil {
		panic(err)
	}
	fmt.Printf("success lock")
}
@WSLUser
Copy link

WSLUser commented Aug 17, 2020

Read this: https://devblogs.microsoft.com/commandline/a-deep-dive-into-how-wsl-allows-windows-to-access-linux-files/ and this https://devblogs.microsoft.com/commandline/whats-new-for-wsl-in-windows-10-version-1903/. Basically this means WSL2 will be unable to support without support being added to the 9P file server (unlikely).

@therealkenc
Copy link
Collaborator

therealkenc commented Aug 17, 2020

Plausible. Other direction too ref #2395 (message).

@nVitius
Copy link

nVitius commented Aug 7, 2021

There's a comment in the golang/go repo that suggests that the 9P protocol does support file-locking, but the implementation used in WSL does not.

Can someone on the WSL team confirm this is the case? If so, can we have any insight into whether or not this will be fixed at some point?
@craigloewen-msft @benhillis

@nVitius
Copy link

nVitius commented Aug 23, 2021

@benhillis @craigloewen-msft
Can we get some feedback on this please?

I haven't seen any other MS employees active in these issues, so I'm pinging you two. If there's someone else that should be involved in this discussion, please let us know.

@ghost
Copy link

ghost commented Feb 1, 2023

This also affects Gradle (a JVM build system).

@michael-ts
Copy link

michael-ts commented Oct 8, 2023

This apparently also affects any programs on Windows which try to use SQLite to open a database on the WSL side (for instance, an ext4 partition mounted using wsl --mount). I can easily reproduce this by creating a simple test database in WSL, then running sqlite3.exe to open it, and execute the SQL statement SELECT * FROM SQLITE_MASTER - this produces this error:

Parse error: database is locked (5)

@oldshensheep
Copy link

\wsl$ also doesn't support watch. Why doesn't WSL use SMB? I set up samba in WSL, it supports both file locking and watch.
I ended up dropping the shit \wsl$, replacing it with SMB

#5103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants