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