SQL_ATTR_LOGIN_TIMEOUT behaviour

Satheesh Subramanian <[email protected]> Tue, 22 Mar 2016 00:34:09 -0700
Newsgroups gmane.comp.db.unixodbc.devel
Message-ID <CALSGBWW4VmhY+8OA_TcHdnnKWWQDGdE9eeQ9qu6wajNtwNn9tQ@mail.gmail.com>
--===============1834117166==
Content-Type: multipart/alternative; boundary=047d7bfd017c2e56b5052e9e3d23

--047d7bfd017c2e56b5052e9e3d23
Content-Type: text/plain; charset=UTF-8

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

--047d7bfd017c2e56b5052e9e3d23
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<div>=C2=A0We ran into a problem where connection to my=
sql=C2=A0database is not timing out within specified SQL_ATTR_LOGIN_TIMEOUT=
 value even when the database is not reachable.</div><div><br></div><div>=
=C2=A0We use UNixODBC driver manager and mysql odbc=C2=A0driver to connect =
to the mysql database. In order to make a connection to the database we do =
the following</div><div>1) Allocate Handle</div><div>2) Set=C2=A0SQL_ATTR_L=
OGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr</div><div>3) Call SQ=
LDriverConnect to make the connection.</div><div><br></div><div>To debug th=
e issue, I first enabled the trace logs and then started to look at the sou=
rce code of unix odbc driver manager.</div><div><br></div><div>By looking a=
t the=C2=A0SQLDriverConnectW.c code, looks like the attribute=C2=A0SQL_ATTR=
_LOGIN_TIMEOUT=C2=A0is only saved to=C2=A0an internal variable as long as t=
he connection state is C2.=C2=A0</div><div><br></div><div>And SQLDriverConn=
ectW.c is trying to load the driver as part pf &quot;part_one_connection&qu=
ot; and then trying to make=C2=A0SQLDriverConnectW call to the mysql=C2=A0o=
dbc 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 somethin=
g 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</div><div><=
br></div><div>I believe this is the reason why login timeout is not getting=
 honoured.=C2=A0</div><div><br></div><div>So, to confirm that, I made=C2=A0=
a change in SQLDriverConnectW to call the mysql driver to set the login tim=
eout(which was saved to internal variable in =C2=A0an earlier call) after l=
oading the driver but before making the actual connection. Afer this change=
, value set for SQL_ATTR_LOGIN_TIMEOUT=C2=A0started to work.</div><div><br>=
</div><div>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 goin=
g through the code multiple times over last few days.</div><div><br></div><=
div>Can someone please point me to the right direction?=C2=A0How does the d=
river manager set the connection timeout to mysql=C2=A0driver? Any help is =
much appreciated!.=C2=A0</div><div><br></div><div>Thanks in advance=C2=A0</=
div></div>

--047d7bfd017c2e56b5052e9e3d23--

--===============1834117166==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============1834117166==--