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

problem with remove lock file in windows #41

Open
allaVolkov opened this issue May 16, 2019 · 3 comments
Open

problem with remove lock file in windows #41

allaVolkov opened this issue May 16, 2019 · 3 comments

Comments

@allaVolkov
Copy link

allaVolkov commented May 16, 2019

The following code works without errors in Unix and ends with error Remove of lock file failed with: remove C:\Users\i019379\go\src\testLocking\lock.lock: The process cannot access the file because it is being used by another process. in Windows.
Thus in Windows it's impossible to remove lock file if more then one process tried to make locking.

func main(){
	wd, _ := os.Getwd()
	lockfile :=  filepath.Join(wd, "lock.lock")
	lock1 := flock.New(lockfile)
	locked1, _ := lock1.TryLock()
	if !locked1{
		fmt.Println("Error - First tryLock failed")
		return
	}
	lock2 := flock.New(lockfile)
	locked2, _ := lock2.TryLock()
	if locked2{
		fmt.Println("Second tryLock succeeded")
		return
	}
	err := lock2.Unlock()
	if err!=nil {
		fmt.Println("Unlock of second lock failed")
		return
	}
	err = lock1.Unlock()
	if err!=nil {
		fmt.Println("Unlock of first lock failed")
		return
	}
	err = os.Remove(lockfile)
	if err!=nil {
		fmt.Println("Remove of lock file failed with: "+err.Error())
		return
	}
}
@theckman
Copy link
Member

@allaVolkov is this still present on v0.7.3? I don't have a Windows system I can test on.

@Integralist
Copy link

I'm seeing this error using Windows via GitHub Actions:

profile_test.go:790: want no error, have error saving config file: error writing to config file: write C:\Users\RUNNER~1\AppData\Local\Temp\fastly-temp-2402719425\config.toml: The process cannot access the file because another process has locked a portion of the file.
[139](https://github.com/fastly/cli/runs/7153347993?check_suite_focus=true#step:11:140)

I'm using version 0.8.1

@ldez
Copy link
Contributor

ldez commented Jun 29, 2024

I tried to reproduce the problem (I use the code in the issue description) on GitHub Action (Windows), but I could not get the error with v0.7.2, v0.7.3, v0.8.0, v0.8.1, and v0.9.0, etc.

I tried:

Version Status
v0.7.0 🔴
v0.7.1 🔴
v0.7.2 🟢
v0.7.3 🟢
v0.8.0 🟢
v0.8.1 🟢
v0.9.0 🟢

So I don't know what to do: the Windows FS is a parallel world where even Go needs a dedicated internal package to "eliminate spurious errors".
https://github.com/golang/go/blob/master/src/cmd/go/internal/robustio/robustio.go

I need something to reproduce the problem with the current version.

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

No branches or pull requests

4 participants