Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TAcNb-0006M7-1R for pgsql-odbc@postgresql.org; Sun, 09 Sep 2012 07:56:31 +0000 Received: from [87.118.86.135] (helo=km31432.keymachine.de) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TAcNU-0002ai-LT for pgsql-odbc@postgresql.org; Sun, 09 Sep 2012 07:56:30 +0000 Received: from localhost.localdomain (unknown [87.242.12.45]) by km31432.keymachine.de (Postfix) with ESMTPSA id 4FFA1390054F; Sun, 9 Sep 2012 07:55:15 +0000 (UTC) Message-ID: <504C4B5F.6080606@cybertec.at> Date: Sun, 09 Sep 2012 09:55:11 +0200 From: Boszormenyi Zoltan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: Hiroshi Inoue CC: Hiroshi Saito , pgsql-odbc@postgresql.org, =?ISO-8859-2?Q?Hans-J=FCrgen_Sch=F6nig?= Subject: Re: Error reporting goes into an infinite loop when compiled --with-odbcver=0x0250 References: <50409E40.10803@cybertec.at> <5041D33B.7020509@tpf.co.jp> <5042284C.1000105@cybertec.at> <50424250.602@cybertec.at> <504A8867.7020103@tpf.co.jp> In-Reply-To: <504A8867.7020103@tpf.co.jp> Content-Type: multipart/mixed; boundary="------------090903030102090205030702" X-Host-Lookup-Failed: Reverse DNS lookup failed for 87.118.86.135 (deferred) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201209/8 X-Sequence-Number: 10947 This is a multi-part message in MIME format. --------------090903030102090205030702 Content-Type: multipart/alternative; boundary="------------000703040907090907070907" --------------000703040907090907070907 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: quoted-printable Hi, 2012-09-08 01:51 keltez=E9ssel, Hiroshi Inoue =EDrta: > Hi, > > Sorry for the late reoly. no problem, it seems you didn't receive the personal copies of my mails. There seems to be a problem with reverse DNS on your side of the of the globe, I got this for the mails in which I sent the attachments: ---8<------8<------8<------8<------8<--- The mail system : host winpg.jp[219.94.251.195] said: 450 4.7.1 Client = host rejected: cannot find your hostname, [87.118.86.135] (in reply to RC= PT TO command) =20 Reporting-MTA: dns; km31432.keymachine.de X-Postfix-Queue-ID: 23F503900523 X-Postfix-Sender: rfc822;zb@cybertec.at Arrival-Date: Fri, 31 Aug 2012 11:21:41 +0000 (UTC) Final-Recipient: rfc822;hiroshi@winpg.jp Original-Recipient:rfc822;hiroshi@winpg.jp Action: failed Status: 4.7.1 Remote-MTA: dns; winpg.jp Diagnostic-Code: smtp; 450 4.7.1 Client host rejected: cannot find your hostname, [87.118.86.135] ---8<------8<------8<------8<------8<--- > (2012/09/02 2:13), Boszormenyi Zoltan wrote: >> Hi, >> >> 2012-09-01 17:22 keltez=E9ssel, Boszormenyi Zoltan =EDrta: >>> Hi, >>> >>> 2012-09-01 11:19 keltez=E9ssel, Hiroshi Inoue =EDrta: >>>> Hi, >>>> >>>> (2012/08/31 20:21), Boszormenyi Zoltan wrote: >>>>> Hi, >>>>> >>>>> we had to recently test psqlODBC with an older application >>>>> which doesn't expect ODBC 3.x. >>>>> >>>>> The problem is that the client locks up as soon as it encounters >>>>> an error of any kind, like restarting the server from under the cli= ent >>>>> or simply executing a bad query. >>>>> >>>>> After debugging the problem and reading the code of both >>>>> unixODBC 2.3.1 and psqlODBC (version 09.00.0310 and 09.01.0200), >>>>> I discovered that the DriverManager calls the driver's SQLError() >>>>> and SQLGetDiagRec() in a loop >>>> >>>> Does the DriverManager call both SQLError() and SQLGetDiagRec()? >>> >>> Yes, it detects which is supported and calls that in the error handle= r >>> part >>> of SQLExecute(). In case psqlODBC is compiled using >>> --with-odbcver=3D0x0250, >>> SQLGetDiagRec() is naturally not supported. >>> >>>> Could you send me (loop part of) the Mylog output? >>> >>> I attached the unixODBC tracefile (/tmp/Trace.txt), there is no "mylo= g" >>> lines in it. I execute a single "select * from test;" and this table >>> doesn't exist. >>> The trace file shows that the error code is repeated ad infinitum. >>> >>> But for my debugging, I didn't use the ODBC tracing, I added my extra >>> printf()s >>> so I can see on the client terminal what is going on. >> >> Attached is the mylog output for the vanilla psqlODBC 09.01.0200 >> which also shows the infinite loop. > > Thanks. > > Clearing error info seems to cause the infinite loop. > > Simply removing the follwoing code would solve the bug. > COuld you try it? > > if (error->errorpos >=3D msglen) > { > ER_Destructor(error); > *pgerror =3D NULL; > } Yes, it also solved the infinite loop. But then using the PODBC_ERROR_CLEAR flag in PGAPI_Error() is unneeded. Nothing else checks for this flag. Attached is the new patch, tested with Valgrind, no leaks found in psqlodbc. The only leaks reported were inside isql and libreadline. > > regards, > Hiroshi Inoue > > > --=20 ---------------------------------- Zolt=E1n B=F6sz=F6rm=E9nyi Cybertec Sch=F6nig & Sch=F6nig GmbH Gr=F6hrm=FChlgasse 26 A-2700 Wiener Neustadt, Austria Web: http://www.postgresql-support.de http://www.postgresql.at/ --------------000703040907090907070907 Content-Type: text/html; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable
Hi,

2012-09-08 01:51 keltez=E9ssel, Hiroshi Inoue =EDrta:
Hi,

Sorry for the late reoly.

no problem, it seems you didn't receive the personal copies of
my mails. There seems to be a problem with reverse DNS
on your side of the of the globe, I got this for the mails in which I sent the attachments:

---8<------8<------8<------8<------8<---
                   The mail system

<h=
iroshi@winpg.jp>: host winpg.jp[219.94.251.195] said: 450 4.7.1 Cl=
ient host
    rejected: cannot find your hostname, [87.118.86.135] (in reply to RCP=
T TO
    command)
=A0
Reporting-MTA: dns; km31432.keymachine.de
X-Postfix-Queue-ID: 23F503900523
X-Postfix-Sender: rfc822; zb@cybertec.at
Arrival-Date: Fri, 31 Aug 2012 11:21:41 +0000 (UTC)

Final-Recipient: rfc822; hiroshi@winpg.jp
Original-Recipient: rfc822;hiroshi@winpg.jp
Action: failed
Status: 4.7.1
Remote-MTA: dns; winpg.jp
Diagnostic-Code: smtp; 450 4.7.1 Client host rejected: cannot find your
    hostname, [87.118.86.135]
---8<------8<------8<------8<------8<---

(2012/09/02 2:13), Boszormenyi Zoltan wrote:
Hi,

2012-09-01 17:22 keltez=E9ssel, Boszormenyi Zoltan =EDrta:
Hi,

2012-09-01 11:19 keltez=E9ssel, Hiroshi Inoue =EDrta:
Hi,

(2012/08/31 20:21), Boszormenyi Zoltan wrote:
Hi,

we had to recently test psqlODBC with an older application
which doesn't expect ODBC 3.x.

The problem is that the client locks up as soon as it encounters
an error of any kind, like restarting the server from under the client
or simply executing a bad query.

After debugging the problem and reading the code of both
unixODBC 2.3.1 and psqlODBC (version 09.00.0310 and 09.01.0200),
I discovered that the DriverManager calls the driver's SQLError()
and SQLGetDiagRec() in a loop

Does the DriverManager call both SQLError() and SQLGetDiagRec()?

Yes, it detects which is supported and calls that in the error handler
part
of SQLExecute(). In case psqlODBC is compiled using
--with-odbcver=3D0x0250,
SQLGetDiagRec() is naturally not supported.

Could you send me (loop part of) the Mylog output?

I attached the unixODBC tracefile (/tmp/Trace.txt), there is no "mylog"
lines in it. I execute a single "select * from test;" and this table
doesn't exist.
The trace file shows that the error code is repeated ad infinitum.

But for my debugging, I didn't use the ODBC tracing, I added my extra
printf()s
so I can see on the client terminal what is going on.

Attached is the mylog output for the vanilla psqlODBC 09.01.0200
which also shows the infinite loop.

Thanks.

Clearing error info seems to cause the infinite loop.

Simply removing the follwoing code would solve the bug.
COuld you try it?

=A0=A0=A0=A0=A0=A0=A0 if (error->errorpos >=3D msglen)
=A0=A0=A0=A0=A0=A0=A0 {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ER_Destructor(error);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 *pgerror =3D NULL;
=A0=A0=A0=A0=A0=A0=A0 }

Yes, it also solved the infinite loop. But then using the
PODBC_ERROR_CLEAR flag in PGAPI_Error() is unneeded.
Nothing else checks for this flag. Attached is the new patch,
tested with Valgrind, no leaks found in psqlodbc. The only
leaks reported were inside isql and libreadline.


regards,
Hiroshi Inoue





--=20
----------------------------------
Zolt=E1n B=F6sz=F6rm=E9nyi
Cybertec Sch=F6nig & Sch=F6nig GmbH
Gr=F6hrm=FChlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
     http://www.postgresql.at/
--------------000703040907090907070907-- --------------090903030102090205030702 Content-Type: text/x-patch; name="psqlodbc-odbc2.5-fix1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="psqlodbc-odbc2.5-fix1.patch" --- psqlodbc-09.01.0200/environ.c.old 2010-08-21 08:29:19.000000000 +0200 +++ psqlodbc-09.01.0200/environ.c 2012-09-09 08:37:38.055625304 +0200 @@ -194,8 +194,7 @@ CSTR func = "ER_ReturnError"; /* CC: return an error of a hstmt */ PG_ErrorInfo *error; - BOOL partial_ok = ((flag & PODBC_ALLOW_PARTIAL_EXTRACT) != 0), - clear_str = ((flag & PODBC_ERROR_CLEAR) != 0); + BOOL partial_ok = ((flag & PODBC_ALLOW_PARTIAL_EXTRACT) != 0); const char *msg; SWORD msglen, stapos, wrtlen, pcblen; @@ -259,15 +258,9 @@ strncpy_null(szSqlState, error->sqlstate, 6); mylog(" szSqlState = '%s',len=%d, szError='%s'\n", szSqlState, pcblen, szErrorMsg); - if (clear_str) - { - error->errorpos = stapos + wrtlen; - if (error->errorpos >= msglen) - { - ER_Destructor(error); - *pgerror = NULL; - } - } + + error->errorpos = stapos + wrtlen; + if (wrtlen == 0) return SQL_SUCCESS_WITH_INFO; else @@ -482,7 +475,7 @@ SQLSMALLINT FAR * pcbErrorMsg) { RETCODE ret; - UWORD flag = PODBC_ALLOW_PARTIAL_EXTRACT | PODBC_ERROR_CLEAR; + UWORD flag = PODBC_ALLOW_PARTIAL_EXTRACT; mylog("**** PGAPI_Error: henv=%p, hdbc=%p hstmt=%d\n", henv, hdbc, hstmt); --------------090903030102090205030702--