From fc5bf6a0ef8814e240975721a2a93da6ac0ea07c Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 15 Apr 2024 12:53:07 +0800 Subject: [PATCH] Clamp TCP_KEEPINTVL and simplify TCP_KEEPALIVE_ABORT_THRESHOLD on Solaris (#292) The time between each consequent probes is set by TCP_KEEPINTVL in seconds. The minimum value is ten seconds. The maximum is ten days, while the default is two hours. The TCP connection will be aborted after certain amount of probes, which is set by TCP_KEEPCNT, without receiving response. ## References [Solaris 11.4](https://docs.oracle.com/cd/E88353_01/html/E37851/tcp-4p.html) Signed-off-by: Andy Pan --- src/anet.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/anet.c b/src/anet.c index 8349895cc..fca1b9a18 100644 --- a/src/anet.c +++ b/src/anet.c @@ -194,6 +194,7 @@ int anetKeepAlive(char *err, int fd, int interval) } intvl = idle/3; + if (intvl < 10) intvl = 10; /* kernel expects at least 10 seconds */ if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl))) { anetSetError(err, "setsockopt TCP_KEEPINTVL: %s\n", strerror(errno)); return ANET_ERR; @@ -216,9 +217,7 @@ int anetKeepAlive(char *err, int fd, int interval) /* Note that the consequent probes will not be sent at equal intervals on Solaris, * but will be sent using the exponential backoff algorithm. */ - intvl = idle/3; - cnt = 3; - int time_to_abort = intvl * cnt; + int time_to_abort = idle; if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, &time_to_abort, sizeof(time_to_abort))) { anetSetError(err, "setsockopt TCP_KEEPCNT: %s\n", strerror(errno)); return ANET_ERR;