SQL_ATTR_LOGIN_TIMEOUT behaviour

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SQL_ATTR_LOGIN_TIMEOUT behaviour

Satheesh Subramanian
Hi,
 We ran into a problem where connection to mysql database is not timing out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the database is not reachable.

 We use UNixODBC driver manager and mysql odbc driver to connect to the mysql database. In order to make a connection to the database we do the following
1) Allocate Handle
2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
3) Call SQLDriverConnect to make the connection.

To debug the issue, I first enabled the trace logs and then started to look at the source code of unix odbc driver manager.

By looking at the SQLDriverConnectW.c code, looks like the attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as long as the connection state is C2. 

And SQLDriverConnectW.c is trying to load the driver as part pf "part_one_connection" and then trying to make SQLDriverConnectW call to the mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored and will never be passed on to mysql driver unless the connection state is something other than C2. Looking at the code connection state would be moved out of S2 state only after a successful connect request to the driver

I believe this is the reason why login timeout is not getting honoured. 

So, to confirm that, I made a change in SQLDriverConnectW to call the mysql driver to set the login timeout(which was saved to internal variable in  an earlier call) after loading the driver but before making the actual connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT started to work.

I am not convinced driver manager would ignore the timeout and I suspect I am doing something wrong. I could not find the reason after going through the code multiple times over last few days.

Can someone please point me to the right direction? How does the driver manager set the connection timeout to mysql driver? Any help is much appreciated!. 

Thanks in advance 

_______________________________________________
unixODBC-dev mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQL_ATTR_LOGIN_TIMEOUT behaviour

Satheesh Subramanian
Please note we are using 
unixODBC version : 2.3.1
mysql odbc driver version : 5.3.4

On Tue, Mar 22, 2016 at 12:34 AM, Satheesh Subramanian <[hidden email]> wrote:
Hi,
 We ran into a problem where connection to mysql database is not timing out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the database is not reachable.

 We use UNixODBC driver manager and mysql odbc driver to connect to the mysql database. In order to make a connection to the database we do the following
1) Allocate Handle
2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
3) Call SQLDriverConnect to make the connection.

To debug the issue, I first enabled the trace logs and then started to look at the source code of unix odbc driver manager.

By looking at the SQLDriverConnectW.c code, looks like the attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as long as the connection state is C2. 

And SQLDriverConnectW.c is trying to load the driver as part pf "part_one_connection" and then trying to make SQLDriverConnectW call to the mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored and will never be passed on to mysql driver unless the connection state is something other than C2. Looking at the code connection state would be moved out of S2 state only after a successful connect request to the driver

I believe this is the reason why login timeout is not getting honoured. 

So, to confirm that, I made a change in SQLDriverConnectW to call the mysql driver to set the login timeout(which was saved to internal variable in  an earlier call) after loading the driver but before making the actual connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT started to work.

I am not convinced driver manager would ignore the timeout and I suspect I am doing something wrong. I could not find the reason after going through the code multiple times over last few days.

Can someone please point me to the right direction? How does the driver manager set the connection timeout to mysql driver? Any help is much appreciated!. 

Thanks in advance 


_______________________________________________
unixODBC-dev mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQL_ATTR_LOGIN_TIMEOUT behaviour

Nick Gorham-2
In reply to this post by Satheesh Subramanian
On 22/03/16 07:34, Satheesh Subramanian wrote:
Hi,
 We ran into a problem where connection to mysql database is not timing out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the database is not reachable.

 We use UNixODBC driver manager and mysql odbc driver to connect to the mysql database. In order to make a connection to the database we do the following
1) Allocate Handle
2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
3) Call SQLDriverConnect to make the connection.

To debug the issue, I first enabled the trace logs and then started to look at the source code of unix odbc driver manager.

Well, checking here with the current build (and I dont see any changes that would affect this) __connect_part_one() contains

    /*
     * set any connection atributes
     */

    DO_ATTR( connection, access_mode, SQL_ATTR_ACCESS_MODE, SQL_ACCESS_MODE );
    DO_ATTR( connection, login_timeout, SQL_ATTR_LOGIN_TIMEOUT, SQL_LOGIN_TIMEOUT );
    DO_ATTR( connection, auto_commit, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT );
    DO_ATTR( connection, async_enable, SQL_ATTR_ASYNC_ENABLE, SQL_ASYNC_ENABLE );
    DO_ATTR( connection, auto_ipd, SQL_ATTR_AUTO_IPD, 0 );
    DO_ATTR( connection, connection_timeout, SQL_ATTR_CONNECTION_TIMEOUT, 0 );
    DO_ATTR( connection, metadata_id, SQL_ATTR_METADATA_ID, 0 );
    DO_ATTR( connection, packet_size, SQL_ATTR_PACKET_SIZE, SQL_PACKET_SIZE );
    DO_ATTR( connection, quite_mode, SQL_ATTR_QUIET_MODE, SQL_QUIET_MODE );
    DO_ATTR( connection, txn_isolation, SQL_ATTR_TXN_ISOLATION, SQL_TXN_ISOLATION );

And SQLSetConnectAttr.c contains

    /*
     * we need to save this even if connected so we can use it for the next connect
     */
    if ( attribute == SQL_ATTR_LOGIN_TIMEOUT )
    {
        connection -> login_timeout = ( SQLLEN ) value;
        connection -> login_timeout_set = 1;
    }

And the comment when this was changed

 * Revision 1.4  2002/01/10 11:17:20  lurcher
 *
 * Allow SQL_ATTR_LOGIN_TIMEOUT to be set when connected to mirror what the
 * MS DM does


2002 is release 2.2.0, so thats been there for some time.

I just tried with one of our (Easysoft) drivers to check, and it seems to work as I would expect, calling SQLSetConnect in the driver between the SQLAllocEnv( SQL_CONNECT ) and the SQLConnect/SQLDriverConnect

--
Nick

_______________________________________________
unixODBC-dev mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev