Re: BUG #3031: PHP (and others?) cannot close a connection when "in" a COPY-statement

From: Arjen van der Meijden <acmmailing(at)tweakers(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3031: PHP (and others?) cannot close a connection when "in" a COPY-statement
Date: 2007-02-20 06:42:17
Message-ID: 45DA9849.2090009@tweakers.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 20-2-2007 4:42 Tom Lane wrote:
> "Arjen van der Meijden" <acmmailing(at)tweakers(dot)net> writes:
>> I'm not sure whether this is a php-issue or a postgresql-client-api one, but
>> when connecting gdb to that process and doing a 'bt' it displays:
>> #0 0xa7c36d9f in free () from /lib/tls/libc.so.6
>> #1 0xa7c38c4f in malloc () from /lib/tls/libc.so.6
>> #2 0xa7f58bdb in PQmakeEmptyPGresult () from /usr/lib/libpq.so.5
>> #3 0xa7f59941 in PQgetResult () from /usr/lib/libpq.so.5
>> #4 0x08086fd0 in _close_pgsql_link (rsrc=0x81e42bc) at
>> /usr/src/php-4.4.2/ext/pgsql/pgsql.c:276
>
> Given that stack trace, you'd better complain to the PHP folk. There is
> no loop in that path in libpq, so the looping must be occurring
> somewhere in the PHP code.

I had a look at that _close_pgsql_link-function and this it the code:

static void _close_pgsql_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
PGconn *link = (PGconn *)rsrc->ptr;
PGresult *res;

while ((res = PQgetResult(link))) {
PQclear(res);
}
PQfinish(link);
PGG(num_links)--;
}

So there is indeed a very clear loop. But I'm not sure whether this code
is incorrect as a generic "close the connection cleanly without memory
leaks"-function? If I duplicate that while-loop to my c-test code it
indeed keeps getting a non-null/false result from PQgetResult and thus
will loop indefinitely.

Do you know a clean example that displays how to close a link cleanly,
including this COPY-situation? Or can you indicate which commands should
be added to do so? My knowledge of the C-api is very limited, so I don't
know what's wrong here.

Best regards,

Arjen

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2007-02-20 07:07:52 Re: BUG #3031: PHP (and others?) cannot close a connection when "in" a COPY-statement
Previous Message Bruce Momjian 2007-02-20 03:47:23 Re: BUG #2913: Subscript on multidimensional array yields no value