flock
flock copied to clipboard
problem with remove lock file in windows
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
}
}
@allaVolkov is this still present on v0.7.3? I don't have a Windows system I can test on.
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