Re: Backend goes in infinite loop when a GUC_REPORT value can’t be converted to client_encoding

From: Jiho Lee <jiho99322(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Rucha Kulkarni <rirukool(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Backend goes in infinite loop when a GUC_REPORT value can’t be converted to client_encoding
Date: 2026-12-03 05:52:55
Message-ID: CAFK+_hess-aH-NjYT+tzgR40ffL149W1jXk+WLqTSTRMVUfsEw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Dec 02, 2026 at 05:23:57PM +0900, Michael Paquier wrote:
> Anyway, your claim that the bug relates to GUC_REPORT is wrong.
> Claude has nicely pointed me out that for example SET SESSION
> AUTHENTICATION with a UTF-8 value loops infinitely with an ERROR if
> client_encoding is switched to something that fails a conversion, say
> a LATIN2. Your suggested fix won't work for that.

I tested this, and session_authorization seems to go through the same
path, since it is GUC_REPORT as well. With v1 applied to master
(f68727292a), SET SESSION AUTHORIZATION to a role named U&"\20AC" with
client_encoding = LATIN1 gives the same WARNING as search_path, and the
session continues. Unless I'm missing a different path, the root
cause is the ParameterStatus conversion either way.

That also means the problem is older than search_path becoming
GUC_REPORT in 18. On a stock 17.12, SET SESSION AUTHORIZATION to that
role loops in the same way. 18 made it reachable for unprivileged
users through search_path.

A few more results that may matter for whichever approach is taken.
Unless noted, these are on master, with and without v1.

1. The looping backend can't be stopped normally. On a stock 18.7,
pg_terminate_backend() returns true but the backend keeps running
at 100% CPU, and "pg_ctl stop -m fast" times out. The server log
grew by about 20k lines per second. As far as I can see, the loop
goes ERROR -> PostgresMain's sigsetjmp block ->
ReportChangedGUCOptions() -> ERROR again, without ever reaching a
CHECK_FOR_INTERRUPTS().

2. The same conversion failure happens at connection start, in
BeginReportingGUCOptions(). On master, a role named U&"\20AC", or
a role with ALTER ROLE ... SET search_path = U&"\20AC", can't
connect with PGCLIENTENCODING=LATIN1 at all: the connection fails
with FATAL. With v1, both connect with a WARNING. I think a
soft-conversion approach should cover this path too.

3. Inside a transaction block, master aborts the transaction (the
error is raised at ReadyForQuery after the SET). It then gets out
of the loop only because ROLLBACK reverts search_path. With v1,
the transaction stays open.

I agree that filtering on the errcode is fragile, and a soft
conversion would also avoid the PG_TRY block. One thing to consider
with a placeholder such as "???": if last_reported then holds the
real value, switching client_encoding back to UTF8 won't resend it,
since only variables flagged GUC_NEEDS_REPORT are reported. The client
would keep the placeholder until the variable changes again. From
reading the code, v1 leaves the client with the same stale value.
Re-flagging such variables when client_encoding changes might be
worth it, but I haven't tested that.

For v1 itself: it builds without warnings, and test_misc (including
the new 017 test) and regress pass.

Regards,
Jiho Lee

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-12-03 05:55:04 Re: DOC: Minor updates for logical replication conflicts
Previous Message Amit Kapila 2026-12-03 05:50:01 Re: ALTER DEFAULT PRIVILEGES IN SCHEMA pg_conflict silently has no effect