NFS cache : file content not updated on client when modified on server

Adding as an answer based on your comment.
The solution is to add lookupcache=none to your nfs mount options.

What happens is that the first time your client reads the file it does a NFS lookup to get the NFS fileid. It then caches the NFS fileid, and when you go back to open the file, it uses the cache. Normally this isnt a problem as when the file is updated its fileid stays the same. But for some reason the old file is being removed, and a new one is created (or renamed, or something to where its not the same file).
Now normally this isnt a problem either as when your client tries to open a fileid which isnt there, it will get an error from the server and do another lookup to get the new fileid. But for some reason the NFS server is letting the client open that old fileid. Perhaps another client has the file open and so its not being deleted yet, I dont know.

In any case the way to solve it is to tell the client to always do an nfslookup before opening a file by using the nfs mount option lookupcache=none. The downside to this is that it can be expensive if you are frequently opening files since it adds more traffic to the NFS server.


You can also manually refresh the NFS cache with

sudo mount /nfs-mount -o remount

...in case you do not want to add any mount options degrading performance.