Skip to content

Commit d899322

Browse files
committed
core: Return BAD_STATEID for NFSv4.0 special "stateless" stateids
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: #160 Related: https://datatracker.ietf.org/doc/html/rfc7530#section-9.1.4.3 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent ad8f569 commit d899322

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ public NFS4Client getClient(clientid4 clientid) throws StaleClientidException {
238238
}
239239

240240
public NFS4Client getClientIdByStateId(stateid4 stateId) throws ChimeraNFSException {
241+
if (Stateids.isStateLess(stateId)) {
242+
// We do not support NFSv4.0 Anonymous/Bypass Stateids:
243+
// https://datatracker.ietf.org/doc/html/rfc7530#section-9.1.4.3
244+
//
245+
// This is occasionally used by macOS NFS when it loses track of its state.
246+
// Returning BAD_STATEID forces a connection-restart.
247+
//
248+
// see nfs_mount_state_error_should_restart (nfs4_vnops.c)
249+
// https://github.com/apple-oss-distributions/NFS/blob/NFS-327.120.3/kext/nfs4_vnops.c#L1863L1880
250+
throw new BadStateidException();
251+
}
241252

242253
_readLock.lock();
243254
try {

0 commit comments

Comments
 (0)