pgsql: postgres_fdw: Fix connection leak. - Mailing list pgsql-committers

From Fujii Masao
Subject pgsql: postgres_fdw: Fix connection leak.
Date
Msg-id E1ktqIA-0008RK-CP@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
postgres_fdw: Fix connection leak.

In postgres_fdw, the cached connections to foreign servers will not be
closed until the local session exits if the user mappings or foreign servers
that those connections depend on are dropped. Those connections can be
leaked.

To fix that connection leak issue, after a change to a pg_foreign_server
or pg_user_mapping catalog entry, this commit makes postgres_fdw close
the connections depending on that entry immediately if current
transaction has not used those connections yet. Otherwise, mark those
connections as invalid and then close them at the end of current transaction,
since they cannot be closed in the midst of the transaction using them.
Closed connections will be remade at the next opportunity if necessary.

Back-patch to all supported branches.

Author: Bharath Rupireddy
Reviewed-by: Zhihong Yu, Zhijie Hou, Fujii Masao
Discussion: https://postgr.es/m/CALj2ACVNcGH_6qLY-4_tXz8JLvA+4yeBThRfxMz7Oxbk1aHcpQ@mail.gmail.com

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b5c73eef8adf5e722564c7e512de761b1a08bfe2

Modified Files
--------------
contrib/postgres_fdw/connection.c              | 33 ++++++++++++++++++++------
contrib/postgres_fdw/expected/postgres_fdw.out | 18 ++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql      | 14 +++++++++++
3 files changed, 58 insertions(+), 7 deletions(-)


pgsql-committers by date:

Previous
From: Bruce Momjian
Date:
Subject: pgsql: Revert "Add key management system" (978f869b99) & later commits
Next
From: Fujii Masao
Date:
Subject: pgsql: postgres_fdw: Fix connection leak.