BUG #18960: Mistake in test test_simple_pipeline (libpq_pipeline.c)

Lists: pgsql-bugs
From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: d(dot)kovalenko(at)postgrespro(dot)ru
Subject: BUG #18960: Mistake in test test_simple_pipeline (libpq_pipeline.c)
Date: 2025-06-18 19:25:04
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18960
Logged by: Dmitry Kovalenko
Email address: d(dot)kovalenko(at)postgrespro(dot)ru
PostgreSQL version: 18beta1
Operating system: any
Description:

Hello,
Please look at these test lines in
src/test/modules/libpq_pipeline/libpq_pipeline.c 1657-1662:
https://github.com/postgres/postgres/blob/c2e2589ab969eb802493191c79de844bf7dc3a6e/src/test/modules/libpq_pipeline/libpq_pipeline.c#L1657-L1662
---
PQclear(res);
res = NULL;
if (PQgetResult(conn) != NULL)
pg_fatal("PQgetResult returned something extra after
pipeline end: %s",
PQresStatus(PQresultStatus(res)));
---
You forgot to assign res:
---
PQclear(res);
res = NULL;
if ((res = PQgetResult(conn)) != NULL)
pg_fatal("PQgetResult returned something extra after
pipeline end: %s",
PQresStatus(PQresultStatus(res)));
---
Thanks&Regards,
Dmitry Kovalenko
PostgresPro, Russia.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: d(dot)kovalenko(at)postgrespro(dot)ru
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18960: Mistake in test test_simple_pipeline (libpq_pipeline.c)
Date: 2025-06-18 21:09:03
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Please look at these test lines in
> src/test/modules/libpq_pipeline/libpq_pipeline.c 1657-1662:
> https://github.com/postgres/postgres/blob/c2e2589ab969eb802493191c79de844bf7dc3a6e/src/test/modules/libpq_pipeline/libpq_pipeline.c#L1657-L1662
> ---
> PQclear(res);
> res = NULL;
> if (PQgetResult(conn) != NULL)
> pg_fatal("PQgetResult returned something extra after
> pipeline end: %s",
> PQresStatus(PQresultStatus(res)));
> ---
> You forgot to assign res:
> ---
> PQclear(res);
> res = NULL;
> if ((res = PQgetResult(conn)) != NULL)
> pg_fatal("PQgetResult returned something extra after
> pipeline end: %s",
> PQresStatus(PQresultStatus(res)));

I agree that's wrong ... but looking around, there's a huge amount
of random inconsistency in this test script --- this same simple
task of checking for an expected NULL result is coded several
different ways with varying amounts of detail provided, and
some other places share this same outright bug.

I think it'd be better to make a helper function
"CheckNoMoreResults(conn)", or something along that line,
to shorten and standardize these places.

On the other side of the coin, the explicit tests for a result
*not* being NULL are mostly unnecessary; if the next step is
a check of PQresultStatus, we could just rely on the fact
that PQresultStatus(NULL) returns PGRES_FATAL_ERROR.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: d(dot)kovalenko(at)postgrespro(dot)ru
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18960: Mistake in test test_simple_pipeline (libpq_pipeline.c)
Date: 2025-06-21 20:01:03
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs

I wrote:
> I agree that's wrong ... but looking around, there's a huge amount
> of random inconsistency in this test script --- this same simple
> task of checking for an expected NULL result is coded several
> different ways with varying amounts of detail provided, and
> some other places share this same outright bug.

> I think it'd be better to make a helper function
> "CheckNoMoreResults(conn)", or something along that line,
> to shorten and standardize these places.

Here's a shot at improving matters. I also made an effort
at cleaning up memory leaks in libpq_pipeline.c, although
that's surely neatnik-ism not anything meaningful.

regards, tom lane

Attachment Content-Type Size
v1-clean-up-libpq-pipeline-tests.patch text/x-diff 30.6 KB

From: Dmitry Kovalenko <d(dot)kovalenko(at)postgrespro(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18960: Mistake in test test_simple_pipeline (libpq_pipeline.c)
Date: 2025-06-21 20:42:42
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs

Hello Tom,

Thank you for your interest in this problem.

+    res = PQgetResult(conn);
+    if (res == NULL)
+        pg_fatal_impl(line, "PQgetResult returned null unexpectedly: %s",
+                      PQerrorMessage(conn));
+    if (PQresultStatus(res) != status)
+        pg_fatal_impl(line, "PQgetResult returned status %s, expected
%s: %s",
+                      PQresStatus(PQresultStatus(res)),
+                      PQresStatus(status),
+                      PQerrorMessage(conn));
+    return res;

As I understand, you have leaks of 'res' when (PQresultStatus(res) !=
status)

I spent the some time to fix a leaks in tests and PG itself here:

https://github.com/dmitry-lipetsk/postgres/commits/D20250617_001-pg_master/

libpq_pipeline.c has not been finished yet but "make check" (under ASAN)
can already executed without any problems.

I hope, you will find something useful in this branch.

For example, these problems are obvious and can be trivially fixed:

https://github.com/dmitry-lipetsk/postgres/commit/484ec68fcfea77beadc19387721d04ca77abe55f

https://github.com/dmitry-lipetsk/postgres/commit/3213f95cfd3e094d6ece4a9114f30f0204c0d056

https://github.com/dmitry-lipetsk/postgres/commit/0d4497a744bd00e741434aa6e307ed23f348fbc4

https://github.com/dmitry-lipetsk/postgres/commit/6f966657d7e9409dcbd8109d41bdc89f22024324

I am planning to return and finish this work near time - I want to get a
clean execution of "make check-world" under ASAN.

Thanks&Regards,

Dmitry Kovalenko


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dmitry Kovalenko <d(dot)kovalenko(at)postgrespro(dot)ru>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18960: Mistake in test test_simple_pipeline (libpq_pipeline.c)
Date: 2025-06-21 21:46:18
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-bugs

Dmitry Kovalenko <d(dot)kovalenko(at)postgrespro(dot)ru> writes:
> As I understand, you have leaks of 'res' when (PQresultStatus(res) !=
> status)

I don't think we really care about leaks when pg_fatal is called.
(If we do, there are a lot of others to worry about.)

> I spent the some time to fix a leaks in tests and PG itself here:
> https://github.com/dmitry-lipetsk/postgres/commits/D20250617_001-pg_master/

Ah, I did not know you were working on this. Perhaps you can merge
what we've done.

regards, tom lane