pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: bufmgr: Fix ordering of checks in PinBuffer()
Date: Wed, 01 Apr 2026 00:27:47 +0000
Message-ID: <E1w7jQw-002NfP-0p@gemulon.postgresql.org> (raw)

bufmgr: Fix ordering of checks in PinBuffer()

The check for skip_if_not_valid added in 819dc118c0f6 was put at the start of
the loop. A CAS loop in theory does allow to make that check in a race free
manner. However, just after the check, there's a
    old_buf_state = WaitBufHdrUnlocked(buf);
which introduces a race, because it would allow BM_VALID to be cleared, after
the skip_if_not_valid check.

Fix by restarting the loop after WaitBufHdrUnlocked().

Reported-by: Yura Sokolov <y.sokolov@postgrespro.ru>
Discussion: https://postgr.es/m/5bf667f3-5270-4b19-a08f-0facbecdff68@postgrespro.ru

Branch
------
master

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

Modified Files
--------------
src/backend/storage/buffer/bufmgr.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)



Message-ID: <E1w7jQw-002NfP-0p@gemulon.postgresql.org>
Permalink:  ../E1w7jQw-002NfP-0p@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w7jQw-002NfP-0p@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: bufmgr: Fix ordering of checks in PinBuffer()
  In-Reply-To: <E1w7jQw-002NfP-0p@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox