BM_IO_ERROR flag is lost in TerminateBufferIO due to order of operations in UnlockBufHdrExt

Yura Sokolov <y.sokolov@postgrespro.ru>

From: Yura Sokolov <y.sokolov@postgrespro.ru>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>, Andres Freund <andres@anarazel.de>
Date: 2026-03-25T14:51:30Z
Lists: pgsql-hackers
Good day, Andres and hackers.

UnlockBufHdrExt does:

   buf_state |= set_bits;
   buf_state &= ~unset_bits;
   buf_state &= ~BM_LOCKED;

TerminateBufferIO unconditionally does:

   unset_flag_bits |= BM_IO_ERROR;

Due to this, AbortBufferIO and buffer_readv_complete_one are failed
to set BM_IO_ERROR with call to TerminateBufferIO.

It was found with proprietary code that was triggered on
PGAIO_RS_ERROR and made assertion on BM_IO_ERROR presence.

-- 
regards
Yura Sokolov aka funny-falcon