winnfsd / vagrant-winnfsd

Manage and adds support for NFS for Vagrant on Windows.
Other
567 stars 62 forks source link

NFS race condition with locked files (Windows 10) #108

Open dev-rke opened 7 years ago

dev-rke commented 7 years ago

Hi,

we found out, that re-indexing files using PHPStorm might let the NFS service freeze for a specific file. This seems to be like a race condition, because sometimes it works for multiple hours, sometimes it dies suddenly after vagrant up.

We have a cache directory in our application for generated files and when PHP is writing to these files, it seems that PHPStorm is indexing this file, so it is reading from this file. Therefore i assume (!) that PHPStorm sets an exclusive lock to this file, and this causes the NFS service to fail. Furthermore the service isn't able to write/read from this file again.

When we set the folder exclusion in PHPStorm for the cache folder (Right click the file/folder, Mark directory as excluded), the issue seems to be gone, but we need to do further testing to ensure this.

Might it be, that the NFS service generally dies, when an exclusive lock to a file exists?

Update: It is not totally fixed, but we can work now for several hours. We also try now to disable Windows firewall and exclude Windows Defender and Microsoft Security Essentials from watching this cache folder. Has anybody else issues with Windows 10? Maybe this also refers to #104, whereas our cache folder is written by the PHP function "file_put_contents".

Environment: Windows 10 PHPStorm 2017.1.3 vagrant 1.9.3

dev-rke commented 7 years ago

Ok, there seems to be definitively an issue with winnfsd. When i lock a file of the cache folder manually in the host (e.g. using Excel to set an exclusive lock), try to write to this file from within the VM (which will result in no change), then unlock the file in the host by closing Excel, i still cannot write to the file again.

marcharding commented 7 years ago

Hey, i'using phpstorm too and do not experience this problem. I'll try to look into it.

dev-rke commented 7 years ago

Do you have files which are changed from inside vagrant? I experience this especially when using file_put_contents and the file is larger than 32kB. The issue happens not all the time, but from time to time. Sometimes the issue occurs after 2 minutes, sometimes you can work up to 4 hours without having the issue. I can successfully reproduce the issue when locking the file in the host operating system.

My temporary workaround: when the issue occurs, i execute a simple php script which just deletes these temporary files. Then the nfs service seems to update the local cached filesystem structure and the file can be created again using file_put_contents.

Just for backreference, i also added a comment in the winnfs project: https://github.com/winnfsd/winnfsd/issues/32

My assumption is, that in the ProcedureWrite (https://github.com/winnfsd/winnfsd/blob/master/src/NFS3Prog.cpp#L712) the cached file system information should be updated. Otherwise write requests only process cached information and the method throws an access error. Unfortunately this would reduce data throughput a little bit, but it would be more reliable as the filesystem information is not provided from cached information.

dev-rke commented 7 years ago

Source of the main issue is found: Windows Defender. It seems Windows Defender seems to lock these files. You definitivly have to restart your machine when you exclude these folders, otherwise Windows Defender won't behave differently. Using other Antiviruses did not produce such issues.

But we still have sometimes (approximatly 2 times a day) in combination with PHPstorm. Therefore i assume there is still a bug in this application.

It's now handleable for us, but it would be great to also fix this bug, therefore i keep this ticket open.

jantomicky commented 6 years ago

@dev-rke Thanks for mentioning the Windows Defender. Helped me solve a problem with gulp outputting a 0 byte file and the NFS server freezing for that specific file until I reloaded Vagrant & the NFS server.

Might be related to https://github.com/winnfsd/vagrant-winnfsd/issues/104 and https://github.com/composer/composer/issues/5707

dev-rke commented 6 years ago

Hi,

i am glad, that you were able to reproduce the issue. :-D

104 is based on this issue.

They need to check if a file is locked on the host, before writing into it. Unfortunately it is impossible to send the information back to the applications inside vagrant, as the NFS protocol does not support file locking. Therefore in my opinion they should set up a FAQ and recommend to exclude project folders from antivirus.