Re: SQL_ATTR_LOGIN_TIMEOUT behaviour
Satheesh Subramanian <[email protected]> Tue, 22 Mar 2016 01:12:21 -0700
| Newsgroups | gmane.comp.db.unixodbc.devel |
|---|---|
| Message-ID | <CALSGBWXwrbEkYfoDQDURFvYu3S1pKK6YkdGWAW5mSHCpNispsw@mail.gmail.com> |
--===============0171427824== Content-Type: multipart/alternative; boundary=001a1145bba2c25970052e9ec585 --001a1145bba2c25970052e9ec585 Content-Type: text/plain; charset=UTF-8 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 < [email protected]> 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 > --001a1145bba2c25970052e9ec585 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Please note we are using=C2=A0<div>unixODBC version : 2.3.= 1</div><div>mysql odbc driver version : 5.3.4</div></div><div class=3D"gmai= l_extra"><br><div class=3D"gmail_quote">On Tue, Mar 22, 2016 at 12:34 AM, S= atheesh Subramanian <span dir=3D"ltr"><<a href=3D"mailto:satheesh101@gma= il.com" target=3D"_blank">[email protected]</a>></span> wrote:<br><b= lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px = #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi,<div>=C2=A0We ran into a p= roblem where connection to mysql=C2=A0database is not timing out within spe= cified 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 o= dbc=C2=A0driver to connect to the mysql database. In order to make a connec= tion to the database we do the following</div><div>1) Allocate Handle</div>= <div>2) Set=C2=A0SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConne= ctAttr</div><div>3) Call SQLDriverConnect to make the connection.</div><div= ><br></div><div>To debug the issue, I first enabled the trace logs and then= started to look at the source code of unix odbc driver manager.</div><div>= <br></div><div>By looking at the=C2=A0SQLDriverConnectW.c code, looks like = the attribute=C2=A0SQL_ATTR_LOGIN_TIMEOUT=C2=A0is only saved to=C2=A0an int= ernal variable as long as the connection state is C2.=C2=A0</div><div><br><= /div><div>And SQLDriverConnectW.c is trying to load the driver as part pf &= quot;part_one_connection" and then trying to make=C2=A0SQLDriverConnec= tW call to the mysql=C2=A0odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOU= T is being ignored and will never be passed on to mysql driver unless the c= onnection state is something other than C2. Looking at the code connection = state would be moved out of S2 state only after a successful connect reques= t to the driver</div><div><br></div><div>I believe this is the reason why l= ogin timeout is not getting honoured.=C2=A0</div><div><br></div><div>So, to= confirm that, I made=C2=A0a change in SQLDriverConnectW to call the mysql = driver to set the login timeout(which was saved to internal variable in =C2= =A0an earlier call) after loading the driver but before making the actual c= onnection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT=C2=A0star= ted to work.</div><div><br></div><div>I am not convinced driver manager wou= ld 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.</div><div><br></div><div>Can someone please point me to the right dir= ection?=C2=A0How does the driver manager set the connection timeout to mysq= l=C2=A0driver? Any help is much appreciated!.=C2=A0</div><div><br></div><di= v>Thanks in advance=C2=A0</div></div> </blockquote></div><br></div> --001a1145bba2c25970052e9ec585-- --===============0171427824== 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 --===============0171427824==--