<div dir="ltr">Hello Sebastian,<div><br></div><div>Have you tried to use `set_reply_close()` instead ?</div><div><br></div><div><a href="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</a><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 10, 2021 at 8:49 PM Sebastian Damm <<a href="mailto:sdamm@pascom.net">sdamm@pascom.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi, <br>
<br>
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.<br>
<br>
This is my code:<br>
<br>
510         if msg.is_method("REGISTER"):<br>
  1             if KSR.pv.get("$shv(MAINTENANCE_MODE)") == 1:<br>
  2                 KSR.info("In maintenance mode, rejecting registration")<br>
  3                 KSR.hdr.append_to_reply("Retry-After: 2\r\n")<br>
  4                 KSR.sl.sl_send_reply(503, "Draining")<br>
  5                 if KSR.tcpops.tcp_set_connection_lifetime(1) > 0:<br>
  6                     KSR.info("Set Connection lifetime to 1")<br>
  7                 return False<br>
<br>
(Side note: msg is some internal class, this is obviously KEMI with python)<br>
<br>
So now when I set the MAINTENANCE_MODE var to 1, Kamailio rejects the REGISTER requests, logs both lines and sends out a 503.<br>
<br>
Debug log tells me this:<br>
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<br>
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<br>
<br>
In tcpdump I can see that the connection does not get closed immediately.<br>
<br>
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.<br>
<br>
<br>
Thanks for any input.<br>
<br>
Regards,<br>
Sebastian<br>
<br>
__________________________________________________________<br>
Kamailio - Users Mailing List - Non Commercial Discussions<br>
  * <a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br>
Important: keep the mailing list in the recipients, do not reply only to the sender!<br>
Edit mailing list options or unsubscribe:<br>
  * <a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Arsen Semenov<br></div><div><br></div></div></div>