Yes, that's a successful connection first. But it helps to get rid of the 
existing connections as well, since there is no new SYN for re-registrations. 
And yes, I want the clients to reconnect. If have disabled the node in the 
loadbalancer before enabling maintenance mode, There won't be any new requests, 
and the existing connections will drain slowly.
________________________________
From: David Villasmil <[email protected]>
Sent: Tuesday, February 6, 2024 13:49
To: Sebastian Damm <[email protected]>
Cc: Kamailio (SER) - Users Mailing List <[email protected]>
Subject: Re: [SR-Users] Get the amount of open TCP connection from routing logic

Thanks for the tips. But wouldn’t that be considered by the load balancer a 
successful connection since there was an ACK to the SYN in order to send the 
503 data? Or does that work for you because you’re relying on the client to 
retry and the load balancer sending to a different server?

Regards,

David Villasmil
email: [email protected]<mailto:[email protected]>
phone: +34669448337


On Tue, 6 Feb 2024 at 13:45, Sebastian Damm 
<[email protected]<mailto:[email protected]>> wrote:
We usually already have a high enough number of max tcp connections. However, 
there are certain scenarios when restarting some of our servers the 
loadbalancer sends all the clients previously connected to these servers to the 
remaining ones, leading to really full and really empty nodes. And sometimes we 
see Kamailio rejecting connections, and sometimes maybe the client can still 
connect, but the outgoing connection to the next hop is not possible anymore.

But maybe you're right. Manually dropping the connection would probably not be 
any better than what Kamailio does after really reaching the limit.

We have already implemented the maintenance mode draining, this would work as 
follows:

Add a shared var named "MAINTENANCE_MODE", set it to 0 in config. Then, when 
handling the REGISTER, add something like this:
        if msg.is_method("REGISTER"):
            if KSR.pv.get("$shv(MAINTENANCE_MODE)") == 1:
                msg.log("In maintenance mode, rejecting registration")
                KSR.set_reply_close()
                KSR.hdr.append_to_reply("Retry-After: 3\r\n")
                KSR.sl.sl_send_reply(503, "Draining")
                return False

You can set the value of the shared var to 1 via kamcmd. After that, on the 
next re-registration, the client will be disconnected, ending up hopefully on a 
different node after reconnect.

Regards,
Sebastian


________________________________
From: David Villasmil 
<[email protected]<mailto:[email protected]>>
Sent: Tuesday, February 6, 2024 13:11
To: Kamailio (SER) - Users Mailing List 
<[email protected]<mailto:[email protected]>>
Cc: Sebastian Damm <[email protected]<mailto:[email protected]>>
Subject: Re: [SR-Users] Get the amount of open TCP connection from routing logic

Why not just increase the max tcp connections? Also, once you hit it, Kamailio 
will reset the syn and the load balancer should try on a different server.

I am look for something like what you’re looking for but reset the sub 
on-demand so I can put the server in maintenance mode.

Regards,

David Villasmil
email: [email protected]<mailto:[email protected]>
phone: +34669448337


On Tue, 6 Feb 2024 at 12:47, Sebastian Damm via sr-users 
<[email protected]<mailto:[email protected]>> wrote:
Hello,

My plan is to reject new inbound requests if there is already a certain number 
of open connections on one Kamailio server. I could answer with a 503 and 
directly close the connection forcing the client to reconnect and the 
loadbalancer to send traffic to a different node on the next connect. It's just 
a last-resort measure to prevent Kamailio from running into the configured TCP 
connection limit (workarounding a poorly-implemented external load balancer).

Since I didn't find anything in the docs: Is there a pseudovariable containing 
the current number of open tcp/tls connections on this Kamailio? I can (and 
already do) query them via kamcmd or rpc, but can I access the variable from 
inside the routing script as well?

Regards,
Sebastian
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to 
[email protected]<mailto:[email protected]>
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:

Reply via email to