]> git.ipfire.org Git - thirdparty/postgresql.git/commit
postgres_fdw: Fix connection leak.
authorFujii Masao <fujii@postgresql.org>
Mon, 28 Dec 2020 11:00:15 +0000 (20:00 +0900)
committerFujii Masao <fujii@postgresql.org>
Mon, 28 Dec 2020 11:00:15 +0000 (20:00 +0900)
commit744357d8461c2760260e599549db96ad078b2a01
treeb6172dd29d73e1e7d9f8b16ae74415de2a56589a
parentd176b9d5e187fc0317f04847fab0d284d467edb8
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
contrib/postgres_fdw/connection.c
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/sql/postgres_fdw.sql