tcp: do not report TCP_CM_INQ of 0 for closed connections
Subsystems (3)
PATCH 1/1 tcp: do not report TCP_CM_INQ of 0 for closed connections
From: Soheil Hassas Yeganeh <[email protected]>
Returning 0 as inq to userspace indicates there is no more data to read, and the application needs to wait for EPOLLIN. For a connection that has received FIN from the remote peer, however, the application must continue reading until getting EOF (return value of 0 from tcp_recvmsg) or an error, if edge-triggered epoll (EPOLLET) is being used. Otherwise, the application will never receive a new EPOLLIN, since there is no epoll edge after the FIN.
Return 1 when there is no data left on the queue but the connection has received FIN, so that the applications continue reading.
--- net/ipv4/tcp.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ipv4/tcp.c +5 -0
@@ -1933,6 +1933,11 @@ static int tcp_inq_hint(struct sock *sk) inq = tp->rcv_nxt - tp->copied_seq;release_sock (sk); } +/* After receiving a FIN, tell the user-space to continue reading +* by returning a non-zero inq. +*/ +if (inq ==0 &&sock_flag (sk,SOCK_DONE )) + inq =1 ;return inq; }
Signature · 1 line
2.21.0.352.gf09ad66450-goog
David Miller
maintainerFrom: Soheil Hassas Yeganeh <[email protected]>
Date: Wed, 6 Mar 2019 13:01:36 -0500
Quoted 14 lines
From: Soheil Hassas Yeganeh <[email protected]>
Returning 0 as inq to userspace indicates there is no more data to read, and the application needs to wait for EPOLLIN. For a connection that has received FIN from the remote peer, however, the application must continue reading until getting EOF (return value of 0 from
tcp_recvmsg) or an error, if edge-triggered epoll (EPOLLET) is being used. Otherwise, the application will never receive a new EPOLLIN, since there is no epoll edge after the FIN.Return 1 when there is no data left on the queue but the connection has received FIN, so that the applications continue reading.
Quoted 5 lines
Fixes b75eba76d3d72 (tcp: send in-queue bytes in cmsg upon read)Signed-off-by Soheil Hassas Yeganeh <[email protected]>Acked-by Neal Cardwell <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Acked-by Yuchung Cheng <[email protected]>
Applied and queued up for -stable, thank you.