Index: sys/kern/uipc_socket.c =================================================================== --- sys/kern/uipc_socket.c +++ sys/kern/uipc_socket.c @@ -4013,20 +4013,26 @@ void soisdisconnected(struct socket *so) { + bool listening; SOCK_LOCK(so); + if (!SOLISTENING(so)) { + SOCKBUF_LOCK(&so->so_rcv); + listening = false; + } else { + listening = true; + } + so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING); so->so_state |= SS_ISDISCONNECTED; - if (!SOLISTENING(so)) { - SOCK_UNLOCK(so); - SOCKBUF_LOCK(&so->so_rcv); + if (!listening) { socantrcvmore_locked(so); SOCKBUF_LOCK(&so->so_snd); sbdrop_locked(&so->so_snd, sbused(&so->so_snd)); socantsendmore_locked(so); - } else - SOCK_UNLOCK(so); + } + SOCK_UNLOCK(so); wakeup(&so->so_timeo); }