[sr-dev] DB Reconnect behaviour in db_unixodbc module

Tim Chubb tim.chubb at voicesimplified.com
Tue Feb 9 14:05:41 CET 2016


Answer own question, re-read c docs and remember how rust my c skills are...
I think the !strncmp was throwing me, to think "if not equal to this or that, then reconnect" rather than !strncmp being short hand for strncmp(...)==0.

With that cleared up in my mind I'm still at a loss as to why only have 2 out of 6 status's deemed worthy of a reconnect attempt.

From: sr-dev [mailto:sr-dev-bounces at lists.sip-router.org] On Behalf Of Tim Chubb
Sent: 09 February 2016 12:49
To: Kamailio (SER) - Development Mailing List <sr-dev at lists.sip-router.org>
Subject: [sr-dev] DB Reconnect behaviour in db_unixodbc module

Hi

Can someone explain the reasoning behind not reconnecting when an ODBC error code of '08003' or '08S01' is received back in modules/db_unixodbc/dbase.c?
Such as on lines 120 and 121?

/* Connection broken */
if( !strncmp((char*)sqlstate,"08003",5) ||
!strncmp((char*)sqlstate,"08S01",5) ) {
ret = reconnect(_h);
if( !SQL_SUCCEEDED(ret) ) return ret;
} else {
return ret;
}

Those error codes equate to Communication link failure and Connection not open both of which are easily handled by a reconnect?
As that logic is used in a few places in dbase.c I figure there must be a reason to exclude those errors from a reconnect, but permit other non-connection related errors to trigger a reconnect?  If the intent was to only allow connection based error codes to attempt a reconnect then wouldn't it make more sense to explicitly define the half dozen or so ODBC connection specific error codes  (the 08xxx range denotes connection related errors) and only permit the ones which could be repaired by a reconnect?

08001 Client unable to establish connection - Can be caused by transient network issue, so a reconnect attempt is valid
08002 Connection name in use - Reconnect probably wouldnt help here
08003 Connection not open - Reconnect would reopen connection
08004 Server rejected the connection - Can be caused by transient network issue such as a reboot, so a reconnect attempt is valid
08007 Connection failure during transaction  - Can be caused by transient network issue, so a reconnect attempt is valid
08S01 Communication link failure - Can be caused by transient network issue, so a reconnect attempt is valid

ODBC Error code definitions: https://msdn.microsoft.com/en-us/library/ms714687%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Of those 6 possible connection related errors only 08002 wouldn't be helped by a reconnect although a new connection could replace the one its attempting to use...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20160209/1e24760a/attachment.html>


More information about the sr-dev mailing list