]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Prevent inconsistent use of stats entry for replication slots
authorMichael Paquier <michael@paquier.xyz>
Wed, 5 Jun 2024 23:48:17 +0000 (08:48 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 5 Jun 2024 23:48:17 +0000 (08:48 +0900)
commitf2c922ff2fed2c17116a625ec7311e8200b1c9f2
treef16e77789c70ceadba3a6ad08f5d781bf274ee24
parentda565f3a4a2e1f04fd85805cbe3965188b330587
Prevent inconsistent use of stats entry for replication slots

Concurrent activity around replication slot creation and drop could
cause a replication slot to use a stats entry it should not have used
when created, triggering an assertion failure when retrieving this
inconsistent entry from the dshash table used by the stats facility.

The issue is that pgstat_drop_replslot() calls pgstat_drop_entry()
without checking the result.  If pgstat_drop_entry() cannot free the
entry related to the object dropped, pgstat_request_entry_refs_gc()
should be called.  AtEOXact_PgStat_DroppedStats() and surrounding
routines dropping stats entries already do that.

This is documented in pgstat_internal.h, but let's add a comment at the
top of pgstat_drop_entry() as that can be easy to miss.

Reported-by: Alexander Lakhin
Author: Floris Van Nee
Analyzed-by: Andres Freund
Discussion: https://postgr.es/m/17947-b9554521ad963c9c@postgresql.org
Backpatch-through: 15
src/backend/utils/activity/pgstat_replslot.c
src/backend/utils/activity/pgstat_shmem.c