[SR-Users] tcp_set_connection_lifetime(1) does not close connection

Sebastian Damm sdamm at pascom.net
Mon Dec 13 09:55:24 CET 2021


Hi,

thanks for the hint. Indeed, this does what I need. Don't know why I didn't find that command. Maybe this thread will help somebody in the future, though.

Regards,
Sebastian

----- Ursprüngliche Mail -----
Von: "Arsen Semenov" <arsperger at gmail.com>
An: "sr-users" <sr-users at lists.kamailio.org>
Gesendet: Samstag, 11. Dezember 2021 08:19:27
Betreff: Re: [SR-Users] tcp_set_connection_lifetime(1) does not close connection

Hello Sebastian, 

Have you tried to use `set_reply_close()` instead ? 

[ https://www.kamailio.org/wiki/cookbooks/5.5.x/core#set_reply_close | https://www.kamailio.org/wiki/cookbooks/5.5.x/core#set_reply_close ] 

On Fri, Dec 10, 2021 at 8:49 PM Sebastian Damm < [ mailto:sdamm at pascom.net | sdamm at pascom.net ] > wrote: 


Hi, 

for having a maintenance mode, I need to implement some sort of draining functionality. All our clients register via TLS. So I thought, I just answer the next REGISTER of a client with a 503 and kill the tcp connection afterwards, so they need to open up a new connection to the loadbalancer in front and end up on a different server. 

This is my code: 

510 if msg.is_method("REGISTER"): 
1 if KSR.pv.get("$shv(MAINTENANCE_MODE)") == 1: 
2 KSR.info("In maintenance mode, rejecting registration") 
3 KSR.hdr.append_to_reply("Retry-After: 2\r\n") 
4 KSR.sl.sl_send_reply(503, "Draining") 
5 if KSR.tcpops.tcp_set_connection_lifetime(1) > 0: 
6 KSR.info("Set Connection lifetime to 1") 
7 return False 

(Side note: msg is some internal class, this is obviously KEMI with python) 

So now when I set the MAINTENANCE_MODE var to 1, Kamailio rejects the REGISTER requests, logs both lines and sends out a 503. 

Debug log tells me this: 
Dec 10 15:32:10 ifens5 /usr/sbin/kamailio[3851]: DEBUG: tcpops [tcpops.c:229]: tcpops_set_connection_lifetime(): new connection lifetime for conid=1: 908866403 
Dec 10 15:32:21 ifens5 /usr/sbin/kamailio[3855]: DEBUG: <core> [core/tcp_main.c:4554]: tcpconn_main_timeout(): entering timer for 0x7f759cb26218 (ticks=908866499, timeout=908866499 (0 s), wr_timeout=0 (211631299 s)), write queue: 0 bytes 

In tcpdump I can see that the connection does not get closed immediately. 

Is there some timer in the tcp stack which cleans up expired connections from time to time? Can I manipulate how often this timer runs? I couldn't find anything, and clearly even though I tell Kamailio to close the connection after 1 second, it doesn't do it. 


Thanks for any input. 

Regards, 
Sebastian 

__________________________________________________________ 
Kamailio - Users Mailing List - Non Commercial Discussions 
* [ mailto:sr-users at lists.kamailio.org | sr-users at lists.kamailio.org ] 
Important: keep the mailing list in the recipients, do not reply only to the sender! 
Edit mailing list options or unsubscribe: 
* [ https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users | https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users ] 


-- 
Arsen Semenov 


__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * sr-users at lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users



More information about the sr-users mailing list