Re: pgbench: make verbose error messages thread-safe

From: Alex Guo <guo(dot)alex(dot)hengchen(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgbench: make verbose error messages thread-safe
Date: 2026-04-24 08:09:06
Message-ID: 6b89a2d4-d661-4b3e-9031-e85db28ed264@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 4/24/26 2:26 PM, Fujii Masao wrote:
> Hi,
>
> While running pgbench with multiple threads and --verbose-errors,
> I found that some verbose error messages were corrupted.
> This issue happens because printVerboseErrorMessages() uses
> a function-local static PQExpBuffer for building those messages.
> Since that buffer is shared across threads, it is not thread-safe.
>
> Attached patch fixes this issue by changing printVerboseErrorMessages()
> to use a local PQExpBufferData instead of a static one. Thoughts?
>
> Since this issue was introduced in v15, the patch should be
> backpatched to v15 if accepted.
>
> Regards,
>
In single-threaded mode, reusing the static local buffer might be
slightly more performant. But if this function needs to be safe in
multi-threaded mode, then we have to stop using a static local variable.

So the change looks reasonable and good to me.

Regards,
Alex Guo

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabrice Chapuis 2026-04-24 08:13:11 question on visibility map
Previous Message Michael Paquier 2026-04-24 08:07:27 Re: pgbench: make verbose error messages thread-safe