Search code examples
tcptime-wait

TIME-WAIT connection refuse to accept a new SYN even it has a lager ISN


According to this SO post Can a TCP port be re-used before TIME-WAIT expires?, TIME-WAIT could be reused if the newly SYN packet has a larger ISN.

But the following SYN failed event if it has a larger ISN than the elder connection.

Detailed info:
Failed SYN: NO(54365) , ISN(3853063683)
Elder connection max packet: NO(50379), ISN(2103445551)

enter image description here


Solution

  • Got it now.

    Both server and client has enabled option 'net.ipv4.tcp_timestamps'(enabled default under centos). So server will first check the timestamp of the newly coming SYN (Ignore ISN now): If it's lager the the corresponding value of the elder connection, then server reuse the TIMEWAIT connection (no matter whether ISN is smaller or lager now). else consider it as a lost packet of the elder connection and send the last ack of the elder connection (no matter whether ISN is smaller or lager now).

    Packet 54365 has a smaller value of timestamp(tsval) than packet 50379, so it fails.

    Useful Refer: https://vincent.bernat.ch/en/blog/2014-tcp-time-wait-state-linux