postgresql/contrib/postgres_fdw
Etsuro Fujita fd5b36ab18 postgres_fdw: Fix handling of abort-cleanup-failed connections.
As connections that failed abort cleanup can't safely be further used,
if a remote query tries to get such a connection, we reject it.
Previously, this rejection involved dropping the connection if it was
open, without accounting for the possibility of open cursors using it,
causing a server crash when such an open cursor tried to use an
already-dropped connection, as a cursor-handling function
(create_cursor, fetch_more_data, or close_cursor) was called on a freed
PGconn.  To fix, delay dropping failed connections until abort cleanup
of the main transaction, to ensure open cursors using such a connection
can safely refer to the PGconn for it.

Oversight in commit 8bf58c0d9.

Reported-by: Zhibai Song <songzhibai1234@gmail.com>
Diagnosed-by: Zhibai Song <songzhibai1234@gmail.com>
Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Discussion: https://postgr.es/m/CAPmGK176y6JP017-Cn%2BhS9CEJx_6iVhRoYbAqzuLU4d8-XPPNg%40mail.gmail.com
Backpatch-through: 14
2026-05-05 18:55:06 +09:00
..
expected postgres_fdw: Fix handling of abort-cleanup-failed connections. 2026-05-05 18:55:06 +09:00
specs postgres_fdw: Add more test coverage for EvalPlanQual testing. 2025-11-06 12:15:05 +09:00
sql postgres_fdw: Fix handling of abort-cleanup-failed connections. 2026-05-05 18:55:06 +09:00
.gitignore Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. 2025-10-15 17:15:05 +09:00
connection.c postgres_fdw: Fix handling of abort-cleanup-failed connections. 2026-05-05 18:55:06 +09:00
deparse.c Fix deparsing of Consts in postgres_fdw ORDER BY 2024-03-11 12:28:40 +13:00
Makefile Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. 2025-10-15 17:15:05 +09:00
option.c Avoid using ambiguous word "non-negative" in error messages. 2021-07-28 01:21:35 +09:00
postgres_fdw--1.0--1.1.sql postgres_fdw: Add functions to discard cached connections. 2021-01-26 15:35:54 +09:00
postgres_fdw--1.0.sql Add postgres_fdw contrib module. 2013-02-21 05:27:16 -05:00
postgres_fdw.c Fix memory leakage in postgres_fdw's DirectModify code path. 2025-05-30 13:45:41 -04:00
postgres_fdw.control postgres_fdw: Add function to list cached connections to foreign servers. 2021-01-18 15:11:08 +09:00
postgres_fdw.h Fix postgres_fdw to check shippability of sort clauses properly. 2022-03-31 14:29:24 -04:00
shippable.c Replace remaining uses of "whitelist". 2021-01-05 14:00:16 +13:00