• Jason Baron's avatar
    tcp: accept RST for rcv_nxt - 1 after receiving a FIN · 0e40f4c9
    Jason Baron authored
    Using a Mac OSX box as a client connecting to a Linux server, we have found
    that when certain applications (such as 'ab'), are abruptly terminated
    (via ^C), a FIN is sent followed by a RST packet on tcp connections. The
    FIN is accepted by the Linux stack but the RST is sent with the same
    sequence number as the FIN, and Linux responds with a challenge ACK per
    RFC 5961. The OSX client then sometimes (they are rate-limited) does not
    reply with any RST as would be expected on a closed socket.
    
    This results in sockets accumulating on the Linux server left mostly in
    the CLOSE_WAIT state, although LAST_ACK and CLOSING are also possible.
    This sequence of events can tie up a lot of resources on the Linux server
    since there may be a lot of data in write buffers at the time of the RST.
    Accepting a RST equal to rcv_nxt - 1, after we have already successfully
    processed a FIN, has made a significant difference for us in practice, by
    freeing up unneeded resources in a more expedient fashion.
    
    A packetdrill test demonstrating the behavior:
    
    // testing mac osx rst behavior
    
    // Establish a connection
    0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
    0.000 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
    0.000 bind(3, ..., ...) = 0
    0.000 listen(3, 1) = 0
    
    0.100 < S 0:0(0) win 32768 <mss 1460,nop,wscale 10>
    0.100 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 5>
    0.200 < . 1:1(0) ack 1 win 32768
    0.200 accept(3, ..., ...) = 4
    
    // Client closes the connection
    0.300 < F. 1:1(0) ack 1 win 32768
    
    // now send rst with same sequence
    0.300 < R. 1:1(0) ack 1 win 32768
    
    // make sure we are in TCP_CLOSE
    0.400 %{
    assert tcpi_state == 7
    }%
    Signed-off-by: default avatarJason Baron <jbaron@akamai.com>
    Cc: Eric Dumazet <edumazet@google.com>
    Acked-by: default avatarEric Dumazet <edumazet@google.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    0e40f4c9
tcp_input.c 183 KB