Re: BUG #18944: Assertion Failure in psql with idle_session_timeout Set

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Cc: n.kalinin@postgrespro.ru, pgsql-bugs@lists.postgresql.org
Date: 2025-06-04T00:12:17Z
Lists: pgsql-bugs
On Tue, Jun 03, 2025 at 11:56:51AM +0200, Anthonin Bonnefoy wrote:
> I've tried to adjust the piped syncs counter, but that's not enough.
> libpq's internal command queue still has the Syncs queued and will
> stay in a busy pipeline state if the backend doesn't send the expected
> ReadyForQuery. It could be possible to remove them from the queue with
> pqCommandQueueAdvance, but that would require psql to include
> libpq-int.h which is probably something we want to avoid.

libpq-int.h is for internal purposes and should not be directly
used in frontends, so that's a no-go.

> It doesn't seem like this case can be handled gracefully. The provided
> patch just aborts the connection from the frontend when excessive
> piped syncs are detected to avoid staying stuck in this inconsistent
> protocol state.

I have been spending some time trying to get psql to gracefully handle
this case, likely as you did by making ExecQueryAndProcessResults()
fail gracefully, but even reinitializing the counters is not enough
and I have also bumped into the libpq limitations.  If somebody is
excited enough to justify exposing these APIs, perhaps they'll have a
good reason and a case to do so, but I'm not excited about doing that
for this psql tooling: we are still able to serialize commands within
a pipeline anyway.

For now I have applied your patch, adding one extra test with COPY TO
on top of the one with COPY FROM.
--
Michael

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. psql: Forbid use of COPY and \copy while in a pipeline

  2. psql: Abort connection when using \syncpipeline after COPY TO/FROM