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

From: Andres Freund <andres(at)anarazel(dot)de>
To: Yura Sokolov <y(dot)sokolov(at)postgrespro(dot)ru>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BM_IO_ERROR flag is lost in TerminateBufferIO due to order of operations in UnlockBufHdrExt
Date: 2026-03-26 20:29:23
Message-ID: xn6ywsqbdmt7h2b7cazwcq4gthn5leg5qwewptq5hdyu3jbjly@odysgph7tdnv
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2026-03-25 17:51:30 +0300, Yura Sokolov wrote:
> 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.

That's clearly not right. Care to write a patch? I think we should add a
test for this in src/test/modules/test_aio too. As we don't rely on things
like BM_IO_ERROR this is quite easy to not notice.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexandre Felipe 2026-03-26 20:49:57 Re: SLOPE - Planner optimizations on monotonic expressions.
Previous Message Andres Freund 2026-03-26 20:26:33 Re: dshash_find_or_insert vs. OOM