Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit

From: Rick Gabriel <klaxian(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit
Date: 2018-04-25 04:02:13
Message-ID: CACvJEPYbk6_YBpTbub6TVCOjKG32RCf=64xv2MQ3mH8rpBMbPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Thank you for investigating! After digging further, I think I found the
problem. It is not technically a bug, but I do have a suggestion to prevent
others from running into the same problem.

First, I forgot to mention that I am sending async queries (PQsendQuery).
libpq documentation states that PQgetResult() must be called repeatedly
until it returns a null pointer. Unfortunately, there is nothing about this
requirement in the official docs for PHP's libpq wrapper extension. If I
don't call PQgetResult() one more time than I really need, the transaction
and connection statuses remain active/busy. Even though PG reports its
status as "busy", subsequent queries succeed normally.

I suggest that the connection and transaction states should be updated when
all queued async queries are completed, without the extra call to
PQgetResult().
What do you think?

On Tue, Apr 24, 2018 at 7:10 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> =?utf-8?q?PG_Bug_reporting_form?= <noreply(at)postgresql(dot)org> writes:
> > PQtransactionStatus() incorrectly returns PQTRANS_ACTIVE after
> committing an
> > empty transaction block (ie. BEGIN and COMMIT without any other queries).
>
> I do not see that here; for instance, the attached test program prints
>
> Initial PQtransactionStatus: 0
> PQtransactionStatus after BEGIN: 2
> PQtransactionStatus after COMMIT: 0
> PQtransactionStatus after BEGIN; COMMIT: 0
>
> which is what I'd expect (0 is PQTRANS_IDLE, 2 is PQTRANS_INTRANS).
> I'd only expect PQTRANS_ACTIVE if libpq thinks a query is still "in
> flight", ie the server hasn't returned a command-complete message.
>
> I speculate that either you or PHP have not waited for the commit
> response to come back ... but without a concrete example to look at,
> it's hard to say more.
>
> regards, tom lane
>
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message jake 2018-04-25 04:30:30 Re: BUG #15168: "pg_isready -d" effectively ignores given database name
Previous Message David G. Johnston 2018-04-25 01:27:07 Re: BUG #15168: "pg_isready -d" effectively ignores given database name