Обсуждение: Infinite loop in pgbench when running COPY command

Поиск
Список
Период
Сортировка

Infinite loop in pgbench when running COPY command

От
Anthonin Bonnefoy
Дата:
Hi,

Currently, pgbench processes a copy response as unexpected and will
move to the error loop. However, PQgetResult will alway return an
empty result when there's no async result through getCopyResult,
leading to an infinite loop in the error handling as res will never be
NULL.

This patch forcefully exits the copy state with PQendcopy before
moving to the error handler, avoiding the infinite loop.

Regards,
Anthonin Bonnefoy

Вложения

Re: Infinite loop in pgbench when running COPY command

От
Michael Paquier
Дата:
On Wed, Oct 01, 2025 at 11:25:00AM +0200, Anthonin Bonnefoy wrote:
> Currently, pgbench processes a copy response as unexpected and will
> move to the error loop. However, PQgetResult will alway return an
> empty result when there's no async result through getCopyResult,
> leading to an infinite loop in the error handling as res will never be
> NULL.
>
> This patch forcefully exits the copy state with PQendcopy before
> moving to the error handler, avoiding the infinite loop.

Fun.  It seems like nobody has ever tested this scenario, even for a
COPY TO.  Why did you try that?  Did you have a benchmark scenario in
mind?

+            case PGRES_COPY_IN:
+            case PGRES_COPY_OUT:
+            case PGRES_COPY_BOTH:
+                pg_log_error("COPY is not supported in pgbench, aborting");
+
+                /*
+                 * We need to exit copy state. Otherwise, PQgetResult will
+                 * always return an empty PGresult from getCopyResult, leading
+                 * to an infinite loop during error cleanup
+                 */
+                PQendcopy(st->con);
+                goto error;

That sounds like a good choice to just fail for the time being, all
these result types don't seem to work (quickly checked).  If somebody
wants to support this case, we could always sort it out, but I am
ready to bet that the odds are in the favor of doing nothing.
--
Michael

Вложения

Re: Infinite loop in pgbench when running COPY command

От
Anthonin Bonnefoy
Дата:
On Thu, Oct 2, 2025 at 10:27 AM Michael Paquier <michael@paquier.xyz> wrote:
> Fun.  It seems like nobody has ever tested this scenario, even for a
> COPY TO.  Why did you try that?  Did you have a benchmark scenario in
> mind?

I was trying to trigger pipeline errors while reviewing the
--continue-client-on-abort pgbench patch. And from past experience,
mixing pipelining and COPY is a good way to trigger those.

> That sounds like a good choice to just fail for the time being, all
> these result types don't seem to work (quickly checked).  If somebody
> wants to support this case, we could always sort it out, but I am
> ready to bet that the odds are in the favor of doing nothing.

Yeah, that was also my take.