tcp_retries2 (integer; default: 15; since Linux 2.2)
The maximum number of times a TCP packet is retransmitted in
established state before giving up. The default value is 15,
which corresponds to a duration of approximately between 13 to
30 minutes, depending on the retransmission timeout. The
RFC 1122 specified minimum limit of 100 seconds is typically
deemed too short.
根据文档TCP_USER_TIMEOUT可以作为补充解决这类问题
https://man7.org/linux/man-pages/man7/tcp.7.html
TCP_USER_TIMEOUT (since Linux 2.6.37)
This option takes an unsigned int as an argument. When the
value is greater than 0, it specifies the maximum amount of
time in milliseconds that transmitted data may remain
unacknowledged before TCP will forcibly close the
corresponding connection and return ETIMEDOUT to the
application. If the option value is specified as 0, TCP will
use the system default.
Increasing user timeouts allows a TCP connection to survive
extended periods without end-to-end connectivity. Decreasing
user timeouts allows applications to "fail fast", if so
desired. Otherwise, failure may take up to 20 minutes with
the current system defaults in a normal WAN environment.
This option can be set during any state of a TCP connection,
but is effective only during the synchronized states of a
connection (ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT,
CLOSING, and LAST-ACK). Moreover, when used with the TCP
keepalive (SO_KEEPALIVE) option, TCP_USER_TIMEOUT will
override keepalive to determine when to close a connection due
to keepalive failure.
The option has no effect on when TCP retransmits a packet, nor
when a keepalive probe is sent.
This option, like many others, will be inherited by the socket
returned by accept(2), if it was set on the listening socket.
Further details on the user timeout feature can be found in
RFC 793 and RFC 5482 ("TCP User Timeout Option").
需求背景
当前Swoole支持tcp keepalive的设置, 可用于解决部分长连接场景下的TCP层面的客户端连接有效性问题,但是在没有触发keepalive机制时,可能无法快速有效的检查出客户端断开(遵循tcp_retries2的设置)
根据文档
TCP_USER_TIMEOUT
可以作为补充解决这类问题需求
TCP_USER_TIMEOUT
进行设置