NFS Server : Issue with "ghost" session

We have a system running AlmaLinux 9.4 which is used as a NFS server. Clients mount the exported filesystem with NFS v4. Clients are VM which are started and stopped on demand.

From time to time, a client VM may be stopped abruptly, and its NFS connection remains active on the server :

  • The session can be found under /proc/fs/nfsd/clients, or visible with nfsdclnts
  • However, there is no active TCP connection between client and server (as seen with ss or netstat)
  • The files opened by the “ghost” client cannot be removed
  • Trying to “revoke the state held by the client” by writing “expire \n” to /proc/fs/nfsd/clients//ctl (as described in nfsd(7) man page) hangs, and needs to be forcibly killed.

The only way we have found to clear up the state used by those “ghost” clients is to restart the NFS server.

Is there someone who face the same issue and how can we solve it or is there any known workaround ?

While neither solution nor workaround, we use automounter (systemd or autofs) on clients to handle most mounts. Since these can automatically umount idle shares, this might mitigate a bit. Of course, if your VM do access share actively while stopping, the automount will not help.

One could also ask what could be done for those stops in the VMs?

Hello jlehtone,
Thank you for your feed back!
Yes indeed we are currently trying to identify which action can cause the ghost session to be created… As it is a little tricky as we don’t have the hand on all the part of the client process we try to securize at NFS server side… we already have set a script which identify ghost session and we would like to automatize the release of such session but as explained trying to “revoke the state held by the client” by writing “expire \n” to /proc/fs/nfsd/clients//ctl (as described in nfsd(7) man page) hangs, and needs to be forcibly killed → Do you know why we face such issue ?
Thank you