public inbox for [email protected]  
help / color / mirror / Atom feed
From: Michael Paquier <[email protected]>
To: Anthonin Bonnefoy <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Fix possible overflow of pg_stat DSA's refcnt
Date: Wed, 26 Jun 2024 14:39:57 +0900
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAO6_XqqJbJBL=M7Ym13TcB4Xnq58vRa2jcC+gwEPBgbAda6B1Q@mail.gmail.com>
References: <CAO6_XqqJbJBL=M7Ym13TcB4Xnq58vRa2jcC+gwEPBgbAda6B1Q@mail.gmail.com>

On Tue, Jun 25, 2024 at 05:01:55PM +0200, Anthonin Bonnefoy wrote:
> During backend initialisation, pgStat DSA is attached using
> dsa_attach_in_place with a NULL segment. The NULL segment means that
> there's no callback to release the DSA when the process exits.
> pgstat_detach_shmem only calls dsa_detach which, as mentioned in the
> function's comment, doesn't include releasing and doesn't decrement the
> reference count of pgStat DSA.
> 
> Thus, every time a backend is created, pgStat DSA's refcnt is incremented
> but never decremented when the backend shutdown. It will eventually
> overflow and reach 0, triggering the "could not attach to dynamic shared
> area" error on all newly created backends. When this state is reached, the
> only way to recover is to restart the db to reset the counter.

Very good catch!  It looks like you have seen that in the field, then.
Sad face.

> This patch fixes this issue by releasing pgStat DSA with
> dsa_release_in_place during pgStat shutdown to correctly decrement the
> refcnt.

Sounds logic to me to do that in the pgstat shutdown callback, ordered
with the dsa_detach calls in a single location rather than registering
a different callback to do the same job.  Will fix and backpatch,
thanks for the report!
--
Michael


Attachments:

  [application/pgp-signature] signature.asc (833B, ../[email protected]/2-signature.asc)
  download

view thread (3+ messages)

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Fix possible overflow of pg_stat DSA's refcnt
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox