[PATCH] select() says closed socket readable

From: Mike Jagdis (jaggy@purplet.demon.co.uk)
Date: Thu Aug 23 2001 - 05:56:03 EST


Whoa! It isn't that select/poll is saying that a read wouldn't
block. It's saying that the socket has been hung up (POLLHUP
not POLLIN)! This is even worse - POLLHUP is always tested
for even of the user didn't ask for it. So if an unconnected
socket appears _anywhere_ in a select or poll we are heading
for spin city, regardless of whether we asked for read, write,
errors or even nothing (in the case of poll)!

Older Linux kernels (2.2.18 at least) blocked on unconnected
TCP sockets but returned POLLHUP on unix sockets. Current
kernels return POLLHUP in both cases. It looks like TCP was
fixed to match unix instead of vice-versa.

A quick poll (<grin>) of available machines here show that
both Sun and FreeBSD block for both TCP and unix unconnected
sockets.

The attached patch _should_ be applied :-).

                                Mike


--- linux.old/net/ipv4/tcp.c Fri Jul 6 13:50:00 2001
+++ linux/net/ipv4/tcp.c Thu Aug 23 11:29:15 2001
@@ -415,11 +415,8 @@
          * then we could set it on SND_SHUTDOWN. BTW examples given
          * in Stevens' books assume exactly this behaviour, it explains
          * why PULLHUP is incompatible with POLLOUT. --ANK
- *
- * NOTE. Check for TCP_CLOSE is added. The goal is to prevent
- * blocking on fresh not-connected or disconnected socket. --ANK
          */
- if (sk->shutdown == SHUTDOWN_MASK || sk->state == TCP_CLOSE)
+ if (sk->shutdown == SHUTDOWN_MASK)
                 mask |= POLLHUP;
         if (sk->shutdown & RCV_SHUTDOWN)
                 mask |= POLLIN | POLLRDNORM;
--- linux.old/net/unix/af_unix.c Tue Jul 24 21:32:01 2001
+++ linux/net/unix/af_unix.c Thu Aug 23 11:31:58 2001
@@ -1711,8 +1711,8 @@
         if (!skb_queue_empty(&sk->receive_queue) || (sk->shutdown&RCV_SHUTDOWN))
                 mask |= POLLIN | POLLRDNORM;
 
- /* Connection-based need to check for termination and startup */
- if (sk->type == SOCK_STREAM && sk->state==TCP_CLOSE)
+ /* Connection-based need to check for termination */
+ if (sk->type == SOCK_STREAM)
                 mask |= POLLHUP;
 
         /*

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Aug 23 2001 - 21:00:55 EST