Re: odbc driver leaks memory when connection failed

Lists: pgsql-odbc
From: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
To: pgsql-odbc(at)postgresql(dot)org
Subject: odbc driver leaks memory when connection failed
Date: 2009-11-18 01:44:26
Message-ID: 4B03517A.5060302@soliton.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Hello,

The psotgre odbc driver seems leak memory when connection failed.

1) A program tries to connect through odbc to a psotgres server running another machine.

2) Remove the network cable from the odbc guest machine ( not from the server machine ).

3) Then memory leaks every time connection fails.

4) Leak size is small when SSL is OFF and big when SSL is ON. 20 KB to 40 KB each when SSL is ON.

5) I tried odbc version 8.3.4 and 8.4.1, and both occurred leak.

Here I try to guess the cause in the odbc driver source code.

socket.c

SOCK_Destructor(SocketClass *self)
{
mylog("SOCK_Destructor\n");
if (!self)
return;
if (self->socket != (SOCKETFD) -1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think this part is wrong and unnecessary. It is because...

When LIBPQ_connect failed to connect on some conditions, it leaves :

- self->sock->socket = -1 and..

- selc->sock->pqconn = pqconn ( unfreed. )

--------------------------------------------------
MORIMOTO Shouji <shoji(dot)morimoto(at)soliton(dot)co(dot)jp>
Soliton Systems +81-3-5360-3830 FAX+81-3-5379-0280


From: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
To: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-18 03:27:20
Message-ID: 4B036998.7020005@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

shoji(dot)morimoto(at)soliton(dot)co(dot)jp wrote:
> Hello,
>
> The psotgre odbc driver seems leak memory when connection failed.

Thanks for your report.
I will take care of your suggestion.

> 1) A program tries to connect through odbc to a psotgres server running another machine.
>
> 2) Remove the network cable from the odbc guest machine ( not from the server machine ).
>
> 3) Then memory leaks every time connection fails.
>
> 4) Leak size is small when SSL is OFF and big when SSL is ON. 20 KB to 40 KB each when SSL is ON.

Does the leak occur even when libpq is not called ?

regards,
Hiroshi Inoue

> 5) I tried odbc version 8.3.4 and 8.4.1, and both occurred leak.
>
>
>
> Here I try to guess the cause in the odbc driver source code.
>
> socket.c
>
> SOCK_Destructor(SocketClass *self)
> {
> mylog("SOCK_Destructor\n");
> if (!self)
> return;
> if (self->socket != (SOCKETFD) -1)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> I think this part is wrong and unnecessary. It is because...
>
> When LIBPQ_connect failed to connect on some conditions, it leaves :
>
> - self->sock->socket = -1 and..
>
> - selc->sock->pqconn = pqconn ( unfreed. )
>
> --------------------------------------------------
> MORIMOTO Shouji <shoji(dot)morimoto(at)soliton(dot)co(dot)jp>
> Soliton Systems +81-3-5360-3830 FAX+81-3-5379-0280


From: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
To: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-18 07:40:41
Message-ID: 4B03A4F9.8030904@soliton.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Thank you Mr. Inoue for your quick comment.

> Does the leak occur even when libpq is not called ?

Yes.

Removed libpq.dll from odbc driver installed folder, and still leaks.

--------------------------------------------------
MORIMOTO Shouji <shoji(dot)morimoto(at)soliton(dot)co(dot)jp>
Soliton Systems +81-3-5360-3830 FAX+81-3-5379-0280

Hiroshi Inoue wrote:


From: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
To: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-18 09:17:18
Message-ID: 4B03BB9E.6040104@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

shoji(dot)morimoto(at)soliton(dot)co(dot)jp wrote:
> Thank you Mr. Inoue for your quick comment.
>
>> Does the leak occur even when libpq is not called ?
>
> Yes.
>
> Removed libpq.dll from odbc driver installed folder, and still leaks.

Hmm what kind of error occur in case
2) Remove the network cable from the odbc guest machine ( not from the
server machine ).
?

regards,
Hiroshi Inoue


From: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
To: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-18 09:39:13
Message-ID: 4B03C0C1.5020800@soliton.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

> Hmm what kind of error occur in case
> 2) Remove the network cable from the odbc guest machine ( not from the
> server machine ).
> ?

Following is a part of mylog_xxxx.log, which includes probably 2 cycle of connection failed.

[4032-104.014][[SQLAllocHandle]][4032-104.014]**** in PGAPI_AllocEnv **
[4032-104.014]** exit PGAPI_AllocEnv: phenv = 0229A270 **
[4032-104.014][[SQLSetEnvAttr]] att=200,3
[4032-104.014][[SQLAllocHandle]][4032-104.016]PGAPI_AllocConnect: entering...
[4032-104.016]**** PGAPI_AllocConnect: henv = 0229A270, conn = 02295008
[4032-104.016]EN_add_connection: self = 0229A270, conn = 02295008
[4032-104.016] added at 0, conn->henv = 0229A270, conns[0]->henv = 0229A270
[4032-104.016][SQLGetInfo(30)][4032-104.018]PGAPI_GetInfo: entering...fInfoType=77
[4032-104.018]PGAPI_GetInfo: p='03.50', len=0, value=0, cbMax=12
[4032-104.018][[SQLSetConnectAttr]] 103
[4032-104.018]PGAPI_SetConnectAttr for 02295008: 103 00000014
[4032-104.018]PGAPI_SetConnectOption: entering fOption = 103 vParam = 20
[4032-104.018][SQLConnect][4032-104.020]PGAPI_Connect: entering..cbDSN=20.
[4032-104.020]getDSNinfo: DSN=Soliton InfoTrace V3 overwrite=1
[4032-104.020]rollback_on_error=0
[4032-104.022]force_abbrev=0 bde=0 cvt_null_date=0
[4032-104.022]globals.extra_systable_prefixes = 'dd_;'
[4032-104.026]calling getDSNdefaults
[4032-104.026]CC_connect: entering...
[4032-104.026]sslmode=require
[4032-104.026]LIBPQ_CC_connect: entering...
[4032-104.027]Driver Version='08.03.0400,200811070001' linking 1400 static Multithread library
[4032-104.029]LIBPQ_CC_connect: DSN = 'Soliton InfoTrace V3', server = '10.30.104.53', port = '9662', database
= 'InfoTraceLog', username = 'infotracels', password='xxxxx'
[4032-104.031]connecting to the database using 10.30.104.53 as the server
[4032-104.031]sizeof connectdb option = 157
[4032-104.031]CC_error_statements: self=02295008
[4032-104.033]CONN ERROR: func=LIBPQ_connect, desc='', errnum=101, errmsg='could not connect to server: No
route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-104.039]Could not establish connection to the database; LIBPQ returned -> could not connect to server:
No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?

[4032-104.041]SOCK_Destructor
[4032-104.041]CONN ERROR: func=PGAPI_Connect, desc='Error on CC_connect', errnum=101, errmsg='could not
connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-104.045]PGAPI_Connect: returning..-1.
[4032-104.045][[SQLGetDiagRec]]
[4032-104.047]PGAPI_GetDiagRec entering type=2 rec=1
[4032-104.047]**** PGAPI_ConnectError: hdbc=02295008 <0>
[4032-104.047]enter CC_get_error
[4032-104.047]enter CC_create_errormsg
[4032-104.047]msg = 'could not connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-104.049]exit CC_create_errormsg
[4032-104.049]exit CC_get_error
[4032-104.049]CC_get_error: status = 101, msg = #could not connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
#
[4032-104.051] szSqlState = '08001',len=159, szError='(null)'
[4032-104.051]PGAPI_GetDiagRec exiting 1
[4032-104.051][[SQLGetDiagRec]]
[4032-104.051]PGAPI_GetDiagRec entering type=2 rec=1
[4032-104.051]**** PGAPI_ConnectError: hdbc=02295008 <161>
[4032-104.053]enter CC_get_error
[4032-104.053]exit CC_get_error
[4032-104.053]CC_get_error: status = 101, msg = #could not connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
#
[4032-104.053] szSqlState = '08001',len=159, szError='could not connect to server: No route to host
(0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-104.055]PGAPI_GetDiagRec exiting 0
[4032-104.057][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=8 info=(012928A8,256)
[4032-104.057]PGAPI_GetDiagField entering rec=1[4032-104.057]PGAPI_GetDiagField exiting 0
[4032-104.057][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=9 info=(012928A8,256)
[4032-104.059]PGAPI_GetDiagField entering rec=1[4032-104.059]PGAPI_GetDiagField exiting 0
[4032-104.059][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=10 info=(012928A8,256)
[4032-104.059]PGAPI_GetDiagField entering rec=1[4032-104.059]PGAPI_GetDiagField exiting 0
[4032-104.061][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=11 info=(012928A8,256)
[4032-104.061]PGAPI_GetDiagField entering rec=1[4032-104.061]PGAPI_GetDiagField exiting 0
[4032-104.061][[SQLGetDiagRec]]
[4032-104.061]PGAPI_GetDiagRec entering type=2 rec=2
[4032-104.061]**** PGAPI_ConnectError: hdbc=02295008 <0>
[4032-104.063]PGAPI_GetDiagRec exiting 100
[4032-105.063][[SQLFreeHandle]][4032-105.063]PGAPI_FreeConnect: entering...
[4032-105.063]**** in PGAPI_FreeConnect: hdbc=02295008
[4032-105.063]enter CC_Destructor, self=02295008
[4032-105.063]in CC_Cleanup, self=02295008
[4032-105.063]after SOCK destructor
[4032-105.063]exit CC_Cleanup
[4032-105.065]after CC_Cleanup
[4032-105.065]after free statement holders
[4032-105.065]exit CC_Destructor
[4032-105.065]PGAPI_FreeConnect: returning...
[4032-105.065][[SQLFreeHandle]][4032-105.065]**** in PGAPI_FreeEnv: env = 0229A270 **
[4032-105.065]in EN_Destructor, self=0229A270
[4032-105.067]clearing conns count=128
[4032-105.067]exit EN_Destructor: rv = 1
[4032-105.067] ok
[4032-105.067][[SQLAllocHandle]][4032-105.067]**** in PGAPI_AllocEnv **
[4032-105.067]** exit PGAPI_AllocEnv: phenv = 0229A270 **
[4032-105.067][[SQLSetEnvAttr]] att=200,3
[4032-105.068][[SQLAllocHandle]][4032-105.068]PGAPI_AllocConnect: entering...
[4032-105.068]**** PGAPI_AllocConnect: henv = 0229A270, conn = 02295008
[4032-105.068]EN_add_connection: self = 0229A270, conn = 02295008
[4032-105.068] added at 0, conn->henv = 0229A270, conns[0]->henv = 0229A270
[4032-105.070][SQLGetInfo(30)][4032-105.070]PGAPI_GetInfo: entering...fInfoType=77
[4032-105.070]PGAPI_GetInfo: p='03.50', len=0, value=0, cbMax=12
[4032-105.070][[SQLSetConnectAttr]] 103
[4032-105.070]PGAPI_SetConnectAttr for 02295008: 103 00000014
[4032-105.070]PGAPI_SetConnectOption: entering fOption = 103 vParam = 20
[4032-105.072][SQLConnect][4032-105.072]PGAPI_Connect: entering..cbDSN=20.
[4032-105.072]getDSNinfo: DSN=Soliton InfoTrace V3 overwrite=1
[4032-105.072]rollback_on_error=0
[4032-105.074]force_abbrev=0 bde=0 cvt_null_date=0
[4032-105.076]globals.extra_systable_prefixes = 'dd_;'
[4032-105.078]calling getDSNdefaults
[4032-105.078]CC_connect: entering...
[4032-105.078]sslmode=require
[4032-105.078]LIBPQ_CC_connect: entering...
[4032-105.080]Driver Version='08.03.0400,200811070001' linking 1400 static Multithread library
[4032-105.084]LIBPQ_CC_connect: DSN = 'Soliton InfoTrace V3', server = '10.30.104.53', port = '9662', database
= 'InfoTraceLog', username = 'infotracels', password='xxxxx'
[4032-105.084]connecting to the database using 10.30.104.53 as the server
[4032-105.084]sizeof connectdb option = 157
[4032-105.086]CC_error_statements: self=02295008
[4032-105.088]CONN ERROR: func=LIBPQ_connect, desc='', errnum=101, errmsg='could not connect to server: No
route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-105.092]Could not establish connection to the database; LIBPQ returned -> could not connect to server:
No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?

[4032-105.094]SOCK_Destructor
[4032-105.096]CONN ERROR: func=PGAPI_Connect, desc='Error on CC_connect', errnum=101, errmsg='could not
connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-105.100]PGAPI_Connect: returning..-1.
[4032-105.100][[SQLGetDiagRec]]
[4032-105.100]PGAPI_GetDiagRec entering type=2 rec=1
[4032-105.100]**** PGAPI_ConnectError: hdbc=02295008 <0>
[4032-105.100]enter CC_get_error
[4032-105.102]enter CC_create_errormsg
[4032-105.102]msg = 'could not connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-105.102]exit CC_create_errormsg
[4032-105.102]exit CC_get_error
[4032-105.104]CC_get_error: status = 101, msg = #could not connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
#
[4032-105.104] szSqlState = '08001',len=159, szError='(null)'
[4032-105.104]PGAPI_GetDiagRec exiting 1
[4032-105.106][[SQLGetDiagRec]]
[4032-105.106]PGAPI_GetDiagRec entering type=2 rec=1
[4032-105.106]**** PGAPI_ConnectError: hdbc=02295008 <161>
[4032-105.106]enter CC_get_error
[4032-105.106]exit CC_get_error
[4032-105.106]CC_get_error: status = 101, msg = #could not connect to server: No route to host (0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
#
[4032-105.108] szSqlState = '08001',len=159, szError='could not connect to server: No route to host
(0x00002751/10065)
Is the server running on host "10.30.104.53" and accepting
TCP/IP connections on port 9662?
'
[4032-105.110]PGAPI_GetDiagRec exiting 0
[4032-105.110][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=8 info=(012928A8,256)
[4032-105.110]PGAPI_GetDiagField entering rec=1[4032-105.110]PGAPI_GetDiagField exiting 0
[4032-105.111][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=9 info=(012928A8,256)
[4032-105.111]PGAPI_GetDiagField entering rec=1[4032-105.111]PGAPI_GetDiagField exiting 0
[4032-105.111][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=10 info=(012928A8,256)
[4032-105.113]PGAPI_GetDiagField entering rec=1[4032-105.113]PGAPI_GetDiagField exiting 0
[4032-105.113][[SQLGetDiagField]] Handle=(2,02295008) Rec=1 Id=11 info=(012928A8,256)
[4032-105.113]PGAPI_GetDiagField entering rec=1[4032-105.113]PGAPI_GetDiagField exiting 0
[4032-105.113][[SQLGetDiagRec]]
[4032-105.115]PGAPI_GetDiagRec entering type=2 rec=2
[4032-105.115]**** PGAPI_ConnectError: hdbc=02295008 <0>
[4032-105.115]PGAPI_GetDiagRec exiting 100

--------------------------------------------------
MORIMOTO Shouji <shoji(dot)morimoto(at)soliton(dot)co(dot)jp>
Soliton Systems +81-3-5360-3830 FAX+81-3-5379-0280


From: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
To: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-18 13:44:36
Message-ID: 4B03FA44.8060602@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

shoji(dot)morimoto(at)soliton(dot)co(dot)jp wrote:
>> Hmm what kind of error occur in case
>> 2) Remove the network cable from the odbc guest machine ( not from the
>> server machine ).
>> ?
>
> Following is a part of mylog_xxxx.log, which includes probably 2 cycle of connection failed.

Could you please try the drivers on testing for 8.4.0101 at
http://www.geocities.jp/inocchichichi/psqlodbc/index.html
?
Probably it still has a small leak.

regards,
Hiroshi Inoue


From: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
To: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-19 05:12:12
Message-ID: 4B04D3AC.6030702@soliton.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

> Could you please try the drivers on testing for 8.4.0101 at
> http://www.geocities.jp/inocchichichi/psqlodbc/index.html
> ?
> Probably it still has a small leak.

Good. The 8.4.0101 did not leak at all (maybe) on my short term ( < 1 hour ) testing.

Regards,

--------------------------------------------------
MORIMOTO Shouji <shoji(dot)morimoto(at)soliton(dot)co(dot)jp>
Soliton Systems +81-3-5360-3830 FAX+81-3-5379-0280


From: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
To: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-19 09:02:19
Message-ID: 4B05099B.3010502@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

shoji(dot)morimoto(at)soliton(dot)co(dot)jp wrote:
>> Could you please try the drivers on testing for 8.4.0101 at
>> http://www.geocities.jp/inocchichichi/psqlodbc/index.html
>> ?
>> Probably it still has a small leak.
>
> Good. The 8.4.0101 did not leak at all (maybe) on my short term ( < 1 hour ) testing.

Thanks.
I would commit the change to cvs.

regards,
Hiroshi Inoue


From: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
To: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-24 02:08:59
Message-ID: 4B0B403B.3090601@soliton.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

Thank you very much for your quick support.

> I would commit the change to cvs.

When do you estimate the date of official release ?

--------------------------------------------------
森本昭治 ソリトンシステムズ 開発部
MORIMOTO Shouji <shoji(dot)morimoto(at)soliton(dot)co(dot)jp>
Soliton Systems +81-3-5360-3830 FAX+81-3-5379-0280


From: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
To: shoji(dot)morimoto(at)soliton(dot)co(dot)jp
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: odbc driver leaks memory when connection failed
Date: 2009-11-26 11:34:16
Message-ID: 4B0E67B8.3080908@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-odbc

shoji(dot)morimoto(at)soliton(dot)co(dot)jp wrote:
> Thank you very much for your quick support.
>
>> I would commit the change to cvs.
>
> When do you estimate the date of official release ?

In ten days or so, maybe.

regards,
Hiroshi Inoue