# NFSv4 File Contents not Updating Automatically



## brxken128 (Jul 22, 2022)

I have some NFS shares exported on my server (13.1-RELEASE), and one of them exports my code to my workstation. I primarily use the `vscode` package for editing my code. My workstation is also running FreeBSD.

I was using 14.0-CURRENT earlier, but as a moderator pointed out, issues such as that are to be expected. I hoped that downgrading would resolve this issue, but it did not (my other issue was fixed though!)

I've noticed a few quirks, and I have been able to reproduce them using other editors (`helix` being the main one). Within VSCode, the "source control"/git area does not automatically update - I *must* manually hit the refresh button for my changes to show.

The process goes as follows:

Open an NFS-mounted directory
Change some of the code
Save the file
Git _should_ automatically refresh within VSCode, but it doesn't
Manually hitting the refresh button does the trick
It gets even worse when it's a file contents conflict, such as when you discard some git changes but VSCode/the editor doesn't update, meaning you either don't actually discard those changes (or the file becomes a jumbled mess).

This issue has persisted across multiple installs of FreeBSD on my workstation, but my server has always been FreeBSD. I did not experience this issue under Linux.

I have the `nfs` shares mounted via fstab:

```
192.168.0.26:/share/code /mnt/code nfs rw,bg,failok,nfsv4 0 0
```

I have full permissions over the remote directory, and I have tried tinkering with the mount options to make sure I cover everything. I have tried:

soft/hard
TCP/UDP
noatime
async/sync
many, many others
None of these have worked, and the file watcher does not seem to update or even detect changes.

I can confirm that all of the issues specified here also happen in the `helix` editor as well. I could have a file open, change+save it, discard within git and those changes would not show once I re-open the file.

I've scoured the web for any related issues, I've checked the VSCode Github just in case there's anything I'm missing, I can't find anything. I have also asked in the FreeBSD Discord, and nobody had many ideas either.

I believe it's an issue with how I'm mounting the share on the client, or something along those lines, but I can't figure out what I'm missing. I'd greatly appreciate any pointers, help, or even ideas - I'm almost completely out of them. Thank you


----------



## ct85711 (Jul 22, 2022)

From what it is sounding like, it seems you are encountering an issue of caching, most likely client side caching.  I don't know what to suggest right off hand, but something you could look at.

https://datatracker.ietf.org/doc/html/rfc2624#section-4.2
Going from the RFC for NFSv4, it does mention client side caching being a design requirement/consideration.  The issue I am seeing from RFC 2624, is that the cache updates are done on file open/close operations.  The key part being, that the files in the applications are actually closing/reopening the files (to flush the cache) and trying to be "smart" and not "fake" close the file while keeping it open to display it faster.


----------



## brxken128 (Jul 22, 2022)

ct85711 said:


> From what it is sounding like, it seems you are encountering an issue of caching, most likely client side caching.  I don't know what to suggest right off hand, but something you could look at.
> 
> https://datatracker.ietf.org/doc/html/rfc2624#section-4.2
> Going from the RFC for NFSv4, it does mention client side caching being a design requirement/consideration.  The issue I am seeing from RFC 2624, is that the cache updates are done on file open/close operations.  The key part being, that the files in the applications are actually closing/reopening the files (to flush the cache) and trying to be "smart" and not "fake" close the file while keeping it open to display it faster.



This does seem to be the issue, although my knowledge in this field is rather limited. The only relevant options I can find are `noac,lookupcache=none`, but I recall trying that earlier and seeing no change (it may be a Linux-only thing). I'll give it another shot!

EDIT: Sadly, neither of these options changed anything. `noac` _is_ mentioned in the `mount_nfs` man page, but I don't see anything else that's relevant in there.

The full NFSv4 specification does mention it, although I'm not too sure what I should be looking for.


----------



## brxken128 (Jul 23, 2022)

I've dug around some more, and it seems as though file locking may somehow be relevant?

Just to confirm my suspicions that it's my mounting/client, I used a Linux client again to mount the exact same share - I couldn't replicate this issue there.

I'm really still not sure what could be causing it.

There's a few things on the NFSv4 man page, but I don't think they're relevant.


----------



## brxken128 (Jul 23, 2022)

I ended up moving to NFSv3, and it seems to have resolved the issue. `vscode` still doesn't update, but I'm going to put that down as a `vscode` quirk.


----------

