[sr-dev] DB API and connection keepalive

Jan Janak jan at ryngle.com
Wed Sep 23 03:59:13 CEST 2009


On Tue, Sep 22, 2009 at 12:55 PM, Jason Penton
<jason.penton at smilecoms.com> wrote:
> Hey Henning,
>
>
> On Tue, Sep 22, 2009 at 12:46 PM, Henning Westerholt
> <henning.westerholt at 1und1.de> wrote:
>>
>> On Dienstag, 22. September 2009, Jason Penton wrote:
>> > Hi Andrei,
>> >
>> > From what I have seen in the code this is pretty useless (no offence).
>> >
>> > The ping in this particular instance is only executed JUST before a real
>> > query is to be issued. i.e. if a query is not used in Kamailio for a
>> > couple
>> > of hours - the ping is actually never sent...........
>>
>> Hi Jason,
>>
>> you're right that its not executed with a timer or similar, but the
>> mysql_ping() should reconnect to the database if the auto reconnect is
>> activated, according the documentation:
>>
>> http://dev.mysql.com/doc/refman/5.0/en/mysql-ping.html
>
> Actually the reconnect doesnt work if your firewall has torn down the
> connection. You can try this with other mysql clients like - the usual
> client, toad, etc. Leave your connection idle for about 45 mins and you will
> see that there's nothing you can do to reconnect.
>
> I have tested this extensively and can only imageine that because the
> firewall has closed the connection, the reconnect in mysql doesnt work -
> because the socket has been torn down underneath mysql (at the OS level). So
> effectively you see a hangin process in Kamailio up to 5 minutes :) which is
> REALLLLLLLLY bad :D

I am not sure I understand. The reconnect option in mysql should be
able to recover from this. It can reconnect even if you restart the
database server. The client library does not really care about the
reason why the connection was lost.

One reason why you might be seeing the long interval is because the
client does not know that the firewall shut the connection down. It
tries to send TCP segments on that connection but they are discarded
by the firewall. In that case it takes time until the socket layer
notifies the mysqlclient library that the connection was lost.

> Ok so I am going to go ahead with using a timer to ping the mysql cons in
> the db_pool. Everyone happy with that?

It probably won't work this way, because you cannot ping all
connections from one process. Every ser/kamailio process opens its own
connection to the database and if you want to send a ping on a
connection, you have to do it in the process which created the
connection.

But that is difficult because most processes are normally suspended in
recvfrom if they do not have a SIP message to process.

   Jan.



More information about the sr-dev mailing list