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
Hello Sebastian,
Have you tried to use `set_reply_close()` instead ?
https://www.kamailio.org/wiki/cookbooks/5.5.x/core#set_reply_close
On Fri, Dec 10, 2021 at 8:49 PM Sebastian Damm sdamm@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
- sr-users@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
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@gmail.com An: "sr-users" sr-users@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@pascom.net | sdamm@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@lists.kamailio.org | sr-users@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 ]
IM trying to see if this can be done to connect to our Kamailio Cluster.
setup a webRTC connection with SDP offer to include SIP to then point to a Kama Cluster to then process as a Sip. (if direct to kamailio then that would be aweome but I think I nneed a TURN/STUN middle box)
If I need to ill look at installing coTurn / Janus gateway to do this. But this doesn’t support trickle ICE so not sure if that will work.
webRTC SDP ==> (coturn or janus)==> SIP (kamailio)
I couldn’t find a way to incorporate a SIP exchange within the SDP message as is there a way to ddo this for a SIP destination / from name but then have reciving rewite that from a SDP exchange.
v=0 o=- 3747690900 3747690900 IN IP4 0.0.0.0 s=a 2 z c=IN IP4 0.0.0.0 t=0 0 a=group:BUNDLE audio0 video0 m=audio 1 RTP/SAVPF 96 0 a=candidate:1 1 UDP 2013266430 xxx.xxx.xxx.xxx 8620 typ host a=ssrc:3643559644 cname:user2571875795@host-433aaf59