bufmgr: Fix order of operations in UnlockBufHdrExt

In c75ebc657ffc I (Andres) introduced UnlockBufHdrExt() which can set and
clear bits in the buffer state using CAS. Unfortunately I added bits before
subtracting them, which means that a bit that was both removed and set would
remain unset.  Fix the order of operations.

The only known case where that is a problem is that BM_IO_ERROR would not
actually remain set.

It's unfortunately not trivial to add a decent, race-free, test to verify that
BM_IO_ERROR remains set. That's therefore left for the 20 cycle.

Reported-by: Yura Sokolov <[email protected]>
Discussion: 
https://postgr.es/m/[email protected]
Backpatch-through: 19, where c75ebc657ffc went in

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/include/storage/buf_internals.h | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

Reply via email to