nfssvc: When the client disconnects, close the socket before sleeping.
authorratchov <ratchov@openbsd.org>
Fri, 12 Jan 2024 08:47:46 +0000 (08:47 +0000)
committerratchov <ratchov@openbsd.org>
Fri, 12 Jan 2024 08:47:46 +0000 (08:47 +0000)
If the server doesn't close the socket immediately and starts waiting
for the client to reconnect, then the TCP connection will remain open.
The client will have to wait for the connection to be closed in order
to reconnect with the same source port; this never happens, resulting
in a freeze until the file system is umounted.

This change fixes Linux NFS clients freezing after 5 min of inactivity.

ok miod, help from claudio

sys/nfs/nfs_syscalls.c

index 45ff763..b19bc36 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: nfs_syscalls.c,v 1.119 2023/08/03 09:49:09 mvs Exp $  */
+/*     $OpenBSD: nfs_syscalls.c,v 1.120 2024/01/12 08:47:46 ratchov Exp $      */
 /*     $NetBSD: nfs_syscalls.c,v 1.19 1996/02/18 11:53:52 fvdl Exp $   */
 
 /*
@@ -331,14 +331,15 @@ loop:
                slp = nfsd->nfsd_slp;
 
                if (ISSET(slp->ns_flag, SLP_VALID)) {
-                       if (ISSET(slp->ns_flag, SLP_DISCONN)) {
-                               nfsrv_zapsock(slp);
-                       } else if (ISSET(slp->ns_flag, SLP_NEEDQ)) {
+                       if ((slp->ns_flag & (SLP_DISCONN | SLP_NEEDQ)) ==
+                           SLP_NEEDQ) {
                                CLR(slp->ns_flag, SLP_NEEDQ);
                                nfs_sndlock(&slp->ns_solock, NULL);
                                nfsrv_rcv(slp->ns_so, (caddr_t)slp, M_WAIT);
                                nfs_sndunlock(&slp->ns_solock);
                        }
+                       if (ISSET(slp->ns_flag, SLP_DISCONN))
+                               nfsrv_zapsock(slp);
 
                        error = nfsrv_dorec(slp, nfsd, &nd);
                        SET(nfsd->nfsd_flag, NFSD_REQINPROG);