| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Rucha Kulkarni <rirukool(at)gmail(dot)com> |
| Cc: | 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-02 08:23:57 |
| Message-ID: | aw_VnTYWuXdCRWK4@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Fri, Nov 27, 2026 at 01:57:14AM +0530, Rucha Kulkarni wrote:
> Any authenticated, unprivileged user can put a backend into an infinite
> retry loop with two commands:
Okay. That's annoying..
> Attached is a patch that fixes the retry loop and downgrades the encoding
> failure to a WARNING instead of an ERROR, since the SET itself had already
> succeeded.
+ /*
+ * The value of this variable is sent to the client just below, so
+ * remove it from the report queue. Otherwise, if sending fails
+ * here, ReportChangedGUCOptions() would try again and warn a
+ * second time.
+ */
+ if (conf->status & GUC_NEEDS_REPORT)
+ {
+ conf->status &= ~GUC_NEEDS_REPORT;
+ slist_delete(&guc_report_list, &conf->report_link);
+ }
ReportGUCOption(conf);
Hmm. Is that OK? Couldn't it be possible that we lose the
information that should be reported because the status flag is cleared
before the report has happened? I like much more the existing idea,
which is to clear the status *after* the report is done.
+ PG_CATCH();
+ {
[...]
+ if (edata->sqlerrcode != ERRCODE_UNTRANSLATABLE_CHARACTER)
+ ReThrowError(edata);
[...]
+ sent = false;
+ }
+ PG_END_TRY();
Filtering what we should do based on an errcode feels like a hack to
me. That won't work here because it's usually not a reliable
long-term solution.
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.
How about relying on mbutils.c instead? We could do a pre-emptive
soft encoding conversion of the value and handle the reports based on
that.. We have routines that do similar work, like
pg_do_encoding_conversion_buf(). If the encoding conversion failed,
one thing could be to be lossy, sending some ASCII with some '?'
characters for the multi-byte sequences we have no idea how to deal
about, or something like that. Or perhaps keep it simpler with an
unknown marker to keep this rare case cheap by design, as an unknown
value would be less confusing than a partially-valid one, say a simple
"???".
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shveta malik | 2026-12-02 08:33:09 | Re: DOC: Minor updates for logical replication conflicts |
| Previous Message | Jakub Wartak | 2026-12-02 08:20:34 | Re: Small WAL replay perf improvements (smgropen()+reduce membarriers for LSN waiters) |