I made working patch on the current master branch:

--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -4324,10 +4324,25 @@ static inline int handle_new_connect(struct socket_info *si)
        struct tcp_connection *tcpconn;
        socklen_t su_len;
        int new_sock;
+       int optval;

        /* got a connection on r */
        su_len = sizeof(su);
        new_sock = accept(si->socket, &(su.s), &su_len);
+
+       if ((optval = TICKS_TO_S(cfg_get(tcp, tcp_cfg, send_timeout)))) {
+               optval *= 1000;
+               if(setsockopt(new_sock, IPPROTO_TCP, TCP_USER_TIMEOUT, &optval,
+                                  sizeof(optval))
+                               < 0) {
+                       LM_WARN("failed to set TCP_USER_TIMEOUT: %s\n",
+                                       strerror(errno));
+               } else {
+                       LM_INFO("Set new connection TCP_USER_TIMEOUT=%d ms\n", optval);
+               }
+       }
+
+
        if(unlikely(new_sock == -1)) {
                if((errno == EAGAIN) || (errno == EWOULDBLOCK))
                        return 0;

Now the retransmits do what is configured and time out after 3s.

Jul 27 18:14:15 p01t-1 kamailio.sbc[1182787]: INFO: <core> [core/tcp_main.c:4373]: handle_new_connect(): Set new connection TCP_USER_TIMEOUT=3000 ms
...
Jul 27 18:14:49 p01t-1 kamailio.sbc[1182775]: INFO: sbc:<script>: >>> Sending Request: INVITE sip:22@192.168.41.157:51151;line=q9yhaejq;ob (10.84.65.131:5082 -> 10.84.65.130:51151: sip:193.84.65.130:51151;transport=tcp)
Jul 27 18:14:52 p01t-1 kamailio.sbc[1182785]: NOTICE: <core> [core/tcp_read.c:267]: tcp_read_data(): error reading: Connection timed out (110) 

Readings:

https://stackoverflow.com/questions/5907527/application-control-of-tcp-retransmission-on-linux
https://man7.org/linux/man-pages/man7/tcp.7.html

Although said "This option, like many others, will be inherited by the socket returned by accept(2), if it was set on the listening socket." => NO, it is not inherited (I tried it after init_sock_keepalive(sock_info->socket); line in tcp_main.c). So it seems it must be done on the spawned socket in handle_new_connect().

Needs more testing and must be done more pretty.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/issues/3443/1653978451@github.com>