Re: Autoprewarm workers terminated due to a segmentation fault - Mailing list pgsql-bugs

From Matheus Alcantara
Subject Re: Autoprewarm workers terminated due to a segmentation fault
Date
Msg-id DJ4VE1MCA80G.1AG5OOFGIWCI0@gmail.com
Whole thread
In response to Re: Autoprewarm workers terminated due to a segmentation fault  (Tomas Vondra <tomas@vondra.me>)
Responses Re: Autoprewarm workers terminated due to a segmentation fault
List pgsql-bugs
On Tue Jun 9, 2026 at 6:44 PM -03, Tomas Vondra wrote:
> So how does it get advanced past the prewarm_stop_idx? I've been unable
> to reproduce it locally, maybe it's platform-specific. The original
> report was from ARM, are you on ARM too, Matheus?
>

Yes, I'm also on ARM. I also set pg_prewarm.autoprewarm_interval=10s on
postgresql.conf, not sure if it make more easier to reproduce.

> But AFAIK the code may not account for read stream callback updating the
> pos to prewarm_stop_idx? The callback may end with (p->pos =
> apw_state->prewarm_stop_idx), and that seems to be past the end of the
> array.
>

Yes, this is my understanding.

> That'd mean the proposed check is generally the correct way to fix this.
> TBH it's not clear to me why this needs to set the *next* entry at the
> end of the loop. Well, it does that so that the loop condition can use
> 'blk', but that seems a bit fragile / confusing, and no one noticed the
> issue.
>
> Maybe this would be a better way to write the while loop?
>
>     while (i < apw_state->prewarm_stop_idx)
>     {
>         blk = block_info[i];
>
>         if (blk.tablespace != tablespace ||
>             blk.filenumber != filenumber)
>             break;
>
>         ...
>     }
>
>

Is attached patch what are you sugesting? If yes, I agree that looks
better, it's more safe and easier to understand.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachment

pgsql-bugs by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: Autoprewarm workers terminated due to a segmentation fault
Next
From: Fujii Masao
Date:
Subject: Re: BUG #19508: pg_buffercache_pages() crashes the backend with an incompatible caller-supplied record definition