From notifications@github.com Tue May 9 09:49:48 2023 From: schoberw To: sr-dev@lists.kamailio.org Subject: [sr-dev] [kamailio/kamailio] tcp_send_timeout not used on reused socket (Issue #3443) Date: Tue, 09 May 2023 02:49:20 -0700 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1389396957==" --===============1389396957== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable ### Description Having clients connected via TCP doing only passive connections in the kamail= io server it seems the tcp_send_timeout is not used on messages going out to = the clients. While tcp_keepalive is doing well as long as there was not sent = any packet to the client tcp_send_timout does nothing. The underlying Linux t= ries to send the SIP message for ages (15 minutes in my case). Do I have a wrong understanding of tcp_send_timeout? I tried with tcp_async yes and no with same results. ### Troubleshooting These are my tcp settings: ``` # def =3D 10 Time in seconds after a TCP connection will be closed if it is n= ot available for writing in this interval (and Kamailio wants to send somethi= ng on it). # Lower this value for faster detection of broken TCP connections. tcp_send_timeout=3D3 tcp_connect_timeout=3D10 # def =3D 10 tcp_connection_lifetime=3D3605 tcp_rd_buf_size=3D32768 tcp_max_connections=3D2048 tcp_connection_match=3D1 # match also local port tcp_keepalive=3Dyes # Enables keepalive for tcp (sets SO_KEEPALIVE sock= et option) tcp_keepcnt=3D3 # Number of keepalives sent before dropping the con= nection (TCP_KEEPCNT socket option). Linux only. tcp_keepidle=3D30 # Time before starting to send keepalives, if the c= onnection is idle (TCP_KEEPIDLE socket option). Linux only. tcp_keepintvl=3D10 # Time interval between keepalive probes, when the = previous probe failed (TCP_KEEPINTVL socket option). Linux only. tcp_async=3Dyes # alias tcp_buf_write, default=3Dyes tcp_crlf_ping=3Dno ``` I also tried to set the tcp_send_timeout to much too high value 333666 to tri= gger this line of code in tcp_options.c: ``` WARN("%s: timeout too big (%u), the maximum value is %u\n", name, *to, max_val); ``` But even in -d -d -d debugging that line never hits. I do **not** make any connections outbound (senseless on NAT). Instead I'd li= ke to reject this: ``` if ($dP =3D~ "tcp") { set_forward_no_connect(); xlog("L_INFO", ">> checking tcp connection to $dd:$dp= "); if(tcp_get_conid("$dd:$dp", "$var(conid)")) { xlog("L_INFO", ">> connection id to $dd:$dp i= s: $var(conid)"); } else { xlog("L_ERR", ">> connection to $dd:$dp is no= longer connected. Client must reregister!"); sl_send_reply("480", "TCP not connected"); exit; } } ``` But the connection ID is still there for a long time. And there are no keepal= ives done since the outgoing packets are in the queue. #### Reproduction 1. Register a client with TCP. 2. Pull the plug. 3. Make a call to it. 4. Run a `'watch 'netstat -tapen | grep '`: The connected client n= ever vanishes. 5. Run a `tcpdump -i ethX tcp port `: the system tries = to send the packet for a long time #### Log Messages There is not much to see in the log, even in debug level. `/usr/sbin/kamailio -P /var/run/kamailio/kamailio.sbc.pid -f /etc/kamailio.sb= c/kamailio.cfg -m 48 -M 24 -u kamailio -g kamailio -d -d -d` At that moment the switchport was already shutdown: ``` May 9 10:48:19 p01t-1 kamailio.sbc[150273]: INFO: sbc: