NFS remote leaks file descriptors and leaves .nfs files behind after each disable/enable cycle
-
Hi, I noticed that every time an NFS backup remote is disabled and re-enabled in Xen Orchestra, a new empty
.nfsfile is created while the previous files remain on the storage.Xen Orchestra built from source, commit 54051163e0, mount options:
hard,proto=tcp,timeo=600,retrans=2The NAS remains available at all times. No network interruption is required to reproduce the issue. I monitored the open file descriptors. Here is an example of consecutive disable/enable cycles:
Remote enabled (3 open descriptors): l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048 l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbff0000004a l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049 Remote disabled (2 open descriptors): l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048 l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049 Remote enabled (4 open descriptors): l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048 l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc010000004b l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049 l-wx------ 1 root root 64 Nov 28 17:16 37 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc020000004c Remote disabled (3 open descriptors): l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048 l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc010000004b l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049 Remote enabled (5 open descriptors): l-wx------ 1 root root 64 Nov 28 17:15 34 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfd00000048 l-wx------ 1 root root 64 Nov 28 17:15 35 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc010000004b l-wx------ 1 root root 64 Nov 28 17:15 36 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddbfe00000049 l-wx------ 1 root root 64 Nov 28 17:16 37 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc040000004d l-wx------ 1 root root 64 Nov 28 17:16 38 -> /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699/.nfs00000000007ddc050000004eDuring an earlier test, I reached 37 open file descriptors. Disabling the remote closed only one of them, leaving 36 still open.
Even though the remote is disabled in XO, the NFS filesystem remains mounted at OS level:
$ findmnt -t nfs,nfs4 TARGET SOURCE FSTYPE OPTIONS /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699 192.168.10.30:/volume1/backup_xcp nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=Trying to unmount it manually results in the following error:
$ sudo umount /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699 umount.nfs4: /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699: device is busyAfter stopping the xo-server service, the same unmount command completes successfully.
This also appears to explain the failed unmount message during the shutdown of the VM running Xen Orchestra:
[FAILED] Failed unmounting /run/xo-server/mounts/e81c1a19-826e-4137-ad0b-e77aecae9699I asked AI to review the source code in
@xen-orchestra/fs/src/_mount.js(https://github.com/vatesfr/xen-orchestra/blob/54051163e0/@xen-orchestra/fs/src/_mount.js) and found the following:const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}` this.#keeper = await fs.open(keeperPath, 'w') ignoreErrors.call(fs.unlink(keeperPath))The creation of
.nfsfiles is expected NFS behaviour because XO intentionally deletes keeper files while keeping their file descriptors open. However, the increasing number of open descriptors is not expected. The observed behaviour suggests that two keeper descriptors are opened during remote activation, but only one is properly closed during deactivation.It may be worth checking whether
_sync()is called twice during remote activation, whether the#keeperreference is overwritten without closing the previous descriptor, or whether multiple handler instances are created for the same remote.Another possible cause is the asynchronous handler clean-up in
packages/xo-server/src/xo-mixins/remotes.mjs.A possible solution would be to ensure that existing keeper descriptors are properly closed before opening new ones, wait for handler clean-up to complete before replacing a handler, and prevent overlapping operations for the same remote. Logging failed close and unmount operations instead of silently ignoring them could also help identify the cause.
The number of open file descriptors should remain stable across repeated disable/enable cycles. Disabling an unused remote should release all associated file descriptors, remove the temporary
.nfsfiles and allow the NFS filesystem to be unmounted.A simple regression test covering repeated disable/enable cycles could help verify this behaviour.
The issue is consistently reproducible, although the exact cause in the source code remains unconfirmed and the proposed changes have not been tested.
Possibly related to #10741, although no NFS server outage or network interruption is required to reproduce this issue.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login