pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Alex Masterov <amasterov@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: Matthias van de Meent <boekewurm+postgres@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Unexpected behavior after OOM errors
Date: Sat, 18 Jul 2026 09:47:43 +0900
Message-ID: <alrNLw6fYc_u7ZP9@paquier.xyz> (raw)
In-Reply-To: <CA+8z=zumV9sscgK=j1Es+-564maVoO9CMDdB9CsW9=FCziCj3w@mail.gmail.com>
References: <e77acaac-a1b3-40b3-99ee-5769b4e453e4@gmail.com>
	<CAEze2Wgktuo+_QWfbALRW-UXXZhbSC+OgGGDFDV9m_BLy5KozQ@mail.gmail.com>
	<ajN2DkXPOzzC1GSj@paquier.xyz>
	<CAEze2Wj3HUz+Z4A8GaoSQyP1V_qGZEkxhp6dquF3+gNyoAmJNw@mail.gmail.com>
	<ajSFcksGRhNJEs5H@paquier.xyz>
	<CAEze2Wjh4_VmtD8C54q2drth2HSkCzBtgMZocuwj=z2gLDFcNQ@mail.gmail.com>
	<ajUkLyWHxCeFVop_@paquier.xyz>
	<ajZFM1XwbDpTQYZV@paquier.xyz>
	<95c64dc2-3abe-4f4e-b285-4c681f565d9f@gmail.com>
	<CA+8z=zumV9sscgK=j1Es+-564maVoO9CMDdB9CsW9=FCziCj3w@mail.gmail.com>

On Fri, Jul 17, 2026 at 04:15:15PM +0200, Alex Masterov wrote:
> The assertion in issue #3 (ent->entry_ref != NULL, pgstat_shmem.c) also has
> a separate trigger I'd like to report — a different code path that poisons
> the same hash in pgstat_get_entry_ref_cached().
> pgstat_get_entry_ref_cached() inserts a zero-filled hash slot — entry_ref
> == NULL — before allocating memory for it. If MemoryContextAlloc() fails
> with OOM it longjmps out, leaving the NULL slot permanently poisoned in
> pgStatEntryRefHash. The hash is backend-local and cross-transaction, so
> abort does not clean it up.
> 
> Crash vectors:
> - Debug builds: backend exit hits Assert(ent->entry_ref != NULL) in
> pgstat_release_matching_entry_refs()
> - Release builds: any GC pass (DROP TABLE etc.) causes
> pgstat_gc_entry_refs() to unconditionally dereference the NULL → SIGSEGV
> 
> This is the backend-local sibling of the shared/DSA-path issue fixed in
> 8191e0c16a. Present since 5891c7a8ed8 (2022); affects PG15, PG17, PG18, and
> master.

Yeah, I can buy this one.  MemoryContextAlloc() would fail an longjmp
on OOM, so we'd better keep the backend data clean.  Perhaps we should
just use the Extended() flavor to bypass the failure and do cleanup
actions..  Will look later.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (32+ messages)  latest in thread

Message-ID: <alrNLw6fYc_u7ZP9@paquier.xyz>
Permalink:  ../alrNLw6fYc_u7ZP9@paquier.xyz/
Also on:    postgresql.org/message-id/alrNLw6fYc_u7ZP9@paquier.xyz

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, amasterov@gmail.com, exclusion@gmail.com, boekewurm+postgres@gmail.com
  Subject: Re: Unexpected behavior after OOM errors
  In-Reply-To: <alrNLw6fYc_u7ZP9@paquier.xyz>
  References: <e77acaac-a1b3-40b3-99ee-5769b4e453e4@gmail.com> <CAEze2Wgktuo+_QWfbALRW-UXXZhbSC+OgGGDFDV9m_BLy5KozQ@mail.gmail.com> <ajN2DkXPOzzC1GSj@paquier.xyz> <CAEze2Wj3HUz+Z4A8GaoSQyP1V_qGZEkxhp6dquF3+gNyoAmJNw@mail.gmail.com> <ajSFcksGRhNJEs5H@paquier.xyz> <CAEze2Wjh4_VmtD8C54q2drth2HSkCzBtgMZocuwj=z2gLDFcNQ@mail.gmail.com> <ajUkLyWHxCeFVop_@paquier.xyz> <ajZFM1XwbDpTQYZV@paquier.xyz> <95c64dc2-3abe-4f4e-b285-4c681f565d9f@gmail.com> <CA+8z=zumV9sscgK=j1Es+-564maVoO9CMDdB9CsW9=FCziCj3w@mail.gmail.com> <alrNLw6fYc_u7ZP9@paquier.xyz>

* 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