Hi PostgreSQL Community, Any authenticated, unprivileged user can put a backend into an infinite retry loop with two commands:
SET client_encoding = 'LATIN1'; SET search_path = U&"\20AC"; -- a euro sign, which has no equivalent in LATIN1 Reproduction: postgres=# SET client_encoding = 'LATIN1'; SET postgres=# SET search_path = U&"\20AC"; SET ERROR: character with byte sequence 0xe2 0x82 0xac in encoding "UTF8" has no equivalent in encoding "LATIN1" ERROR: character with byte sequence 0xe2 0x82 0xac in encoding "UTF8" has no equivalent in encoding "LATIN1" ERROR: character with byte sequence 0xe2 0x82 0xac in encoding "UTF8" has no equivalent in encoding "LATIN1" [... repeats forever; no prompt returns ...] It never comes back to a prompt, and the backend keeps running in the background regardless, taking up CPU and writing to the server log nonstop, which can eventually fill up the disk. This happens because search_path became GUC_REPORT in PG 18 (commit <https://github.com/postgres/postgres/commit/28a1121fd91235e09793c9ce64cb5539719afa30>). ReportChangedGUCOptions() only clears GUC_NEEDS_REPORT and removes the entry from guc_report_list after calling ReportGUCOption(). When the value can’t be converted to the client’s encoding, that call throws, skipping the cleanup, so the entry stays pending and gets retried every ReadyForQuery cycle, forever. The backend never reaches ReadyForQuery or reads from the client, so it outlives a disconnect and logs unboundedly. Confirmed on master and PG 18.7. 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. Thanks, Rucha Kulkarni
v1-0001-Avoid-infinite-retry-loop-when-a-GUC_REPORT-value.patch
Description: Binary data
