Fix race condition in InvalidatePossiblyObsoleteSlot()

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: exclusion(at)gmail(dot)com, michael(at)paquier(dot)xyz
Subject: Fix race condition in InvalidatePossiblyObsoleteSlot()
Date: 2024-01-15 07:48:43
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi hackers,

While working on [1], we discovered (thanks Alexander for the testing) that an
conflicting active logical slot on a standby could be "terminated" without
leading to an "obsolete" message (see [2]).

Indeed, in case of an active slot we proceed in 2 steps in

- terminate the backend holding the slot
- report the slot as obsolete

This is racy because between the two we release the mutex on the slot, which
means that the slot's effective_xmin and effective_catalog_xmin could advance
during that time (leading to exit the loop).

I think that holding the mutex longer is not an option (given what we'd to do
while holding it) so the attached proposal is to record the effective_xmin and
effective_catalog_xmin instead that was used during the backend termination.


Looking forward to your feedback,


Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services:

Attachment Content-Type Size
v1-0001-Fix-race-condition-in-InvalidatePossiblyObsoleteS.patch text/x-diff 2.6 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2024-01-15 07:49:44 Re: pgbnech: allow to cancel queries during benchmark
Previous Message Masahiko Sawada 2024-01-15 07:03:41 Re: Make COPY format extendable: Extract COPY TO format implementations