Fix memory leak in pgoutput with streamed prepared transactions.

pgoutput records the toplevel XID in the relation's streamed_txns
list, allocated in CacheMemoryContext, when it sends a relation's
schema during a streamed transaction. We clean up that list at stream
commit and stream abort, but missed stream prepare, so the XIDs stay
around until a relcache invalidation for the relation or until the
walsender exits.

Fix by cleaning up the cache after writing the stream prepare message,
marking the schema as sent as we do at stream commit. The subscriber
applies the spooled relation messages at PREPARE time and its relation
map isn't rolled back by ROLLBACK PREPARED, so we don't need to send
the schema again even if the prepared transaction eventually aborts.

Oversight in commit 63cf61cdeb7b.

Author: Ayush Tiwari <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Discussion: 
https://postgr.es/m/CAJTYsWWt5aaKHCnV=jnowabzspd-wbnhwlnddqtesdqrq-b...@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_18_STABLE

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

Modified Files
--------------
src/backend/replication/pgoutput/pgoutput.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)

Reply via email to