From 726e54529dc8e55268b40c18e4bfd08d69973a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Tue, 8 Jul 2025 20:33:19 +0200 Subject: [PATCH] core: Return BAD_STATEID for NFSv4.0 special "stateless" stateids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Under some rare circumstances, especially when under I/O pressure, NFS clients such as those on macOS may try to send NFS requests with an invalid state id (seq=-1, other:ffffffffffffffffffffffff; or seq:0, other:0). This usually happens after the NFS server has been restarted and lost information about the previous client state. Unfortunately, the macOS client does not recover from this situation and keeps making requests to the server. This slows down both server and client to a halt. Send a "bad stateid" error upon occurring such a sequence. This lets the NFS client reconnect and re-establish the correct state with the server. Fixes: https://github.com/dCache/nfs4j/issues/160 Related: https://datatracker.ietf.org/doc/html/rfc7530#section-9.1.4.3 Signed-off-by: Christian Kohlschütter --- .../java/org/dcache/nfs/v4/NFSv4StateHandler.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java b/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java index b7d64a4d..b6dd36c6 100644 --- a/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java +++ b/core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java @@ -238,6 +238,17 @@ public NFS4Client getClient(clientid4 clientid) throws StaleClientidException { } public NFS4Client getClientIdByStateId(stateid4 stateId) throws ChimeraNFSException { + if (Stateids.isStateLess(stateId)) { + // We do not support NFSv4.0 Anonymous/Bypass Stateids: + // https://datatracker.ietf.org/doc/html/rfc7530#section-9.1.4.3 + // + // This is occasionally used by macOS NFS when it loses track of its state. + // Returning BAD_STATEID forces a connection-restart. + // + // https://github.com/apple-oss-distributions/NFS/blob/NFS-327.120.3/kext/nfs4_vnops.c#L2813 + // https://github.com/apple-oss-distributions/NFS/blob/NFS-327.120.3/kext/nfs4_vnops.c#L1863L1880 + throw new BadStateidException(); + } _readLock.lock(); try {