Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Txdy3-0008JN-7V for pgsql-odbc@arkaria.postgresql.org; Tue, 22 Jan 2013 13:32:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Txdy2-0007PA-OY for pgsql-odbc@arkaria.postgresql.org; Tue, 22 Jan 2013 13:32:46 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Txdy2-0007P4-7c for pgsql-odbc@postgresql.org; Tue, 22 Jan 2013 13:32:46 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Txdy1-0005Mo-3z for pgsql-odbc@postgresql.org; Tue, 22 Jan 2013 13:32:45 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1Txdy0-0001dp-Re for pgsql-odbc@postgresql.org; Tue, 22 Jan 2013 05:32:44 -0800 Date: Tue, 22 Jan 2013 05:32:44 -0800 (PST) From: mkocherov To: pgsql-odbc@postgresql.org Message-ID: <1358861564828-5741621.post@n5.nabble.com> Subject: EN_Destructor bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: 0.0 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org Hello! 1) We observe crashes in psqlodbc.so library from time to time. Crash dumps typically look like this one: #0 0x0057f420 in __kernel_vsyscall () #1 0x09ba7df0 in raise () from /lib/libc.so.6 #2 0x09ba9701 in abort () from /lib/libc.so.6 #3 0x09bdebcb in __libc_message () from /lib/libc.so.6 #4 0x09be6fea in _int_free () from /lib/libc.so.6 #5 0x09be7329 in free () from /lib/libc.so.6 #6 0x02c601d0 in EN_Destructor () from /usr/pgsql-9.0/lib/psqlodbc.so #7 0x02c60224 in PGAPI_FreeEnv () from /usr/pgsql-9.0/lib/psqlodbc.so #8 0x02c8f3fe in SQLFreeHandle () from /usr/pgsql-9.0/lib/psqlodbc.so #9 0x00e961e5 in ?? () from /usr/lib/libodbc.so.1 #10 0x00e9666d in ?? () from /usr/lib/libodbc.so.1 #11 0x00e96760 in ?? () from /usr/lib/libodbc.so.1 #12 0x00e9d02e in SQLDisconnect () from /usr/lib/libodbc.so.1 =E2=80=A6 Due to nature of our program it makes frequent connect / disconnects in parallel threads. ODBC threading level is set to 2, e.g.: [PostgreSQL] Description =3D PostgreSQL driver Driver =3D /usr/pgsql-9.0/lib/psqlodbc.so Setup =3D /usr/pgsql-9.0/lib/psqlodbc.so FileUsage =3D 1 Threading =3D 2 2) Checking code of driver reveals that it doesn=E2=80=99t protect shared c= onnection list when making cleanup tasks in EN_Destructor (PGAPI_FreeEnv -> EN_Destructor). In this function there is no ENTER_CONNS_CS / LEAVE_CONNS_CS; 3) In 2005 Tom Hughes (http://postgresql.1045698.n5.nabble.com/EN-Destructor-bug-td2187457.html) provided patch that fixed this problem but then his changes were lost (starting from psqlodbc-08.02.0100 version). 4) The problem was reproduced on latest stock drivers psqlodbc-09.00.0310 and psqlodbc-09.01.0200.=20 5) When logging to mylog is enrolled then problem is hardly reproduced =E2= =80=93 it seems parallels calls are effectively serialized within mylog() function. 6) Problem is somewhat mitigated by the fact that default threading level in unixODBC is set to 3 which eventually prevents races in psqlodbc driver. 7) Patch: --- environ.c.van 2010-08-21 10:29:19.000000000 +0400 +++ environ.c 2013-01-17 18:47:12.000000000 +0300 @@ -583,6 +583,7 @@ */ /* Free any connections belonging to this environment */ + ENTER_CONNS_CS; for (lf =3D 0, nullcnt =3D 0; lf < conns_count; lf++) { if (NULL =3D=3D conns[lf]) @@ -603,6 +604,7 @@ conns =3D NULL; conns_count =3D 0; } + LEAVE_CONNS_CS; DELETE_ENV_CS(self); free(self); Thanks! Michael Kocherov Software Developer Parallels Automation Maintenance -- View this message in context: http://postgresql.1045698.n5.nabble.com/EN-De= structor-bug-tp5741621.html Sent from the PostgreSQL - odbc mailing list archive at Nabble.com. --=20 Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc