From: Nathan Bossart <nathandbossart@gmail.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: pgsql: Teach DSM registry to ERROR if attaching to an uninitialized ent
Date: Tue, 25 Nov 2025 11:45:34 -0600
Message-ID: <aSXrPqV3Bcm2HLV4@nathan> (raw)
In-Reply-To: <CA+TgmobGYDczmVa-UDGPgcyN=63PJzzyQ9ZCofou4VYH8TVLSQ@mail.gmail.com>
References: <aR-fqzfZYSd3TVKa@nathan>
<CA+TgmoZsxbVhoxNGTWSd6=vHvyoqOSDNXJZabBZx+St8uPduLQ@mail.gmail.com>
<aSIR4Z4U887f_KcQ@nathan>
<aSSlqWwLVuXMmN-o@nathan>
<aSSr6j3JzeLcqOWo@nathan>
<CA+TgmoYq7U0hHgOEOqQgf=6cFXz_7Ab8QTRMFqFpLNfav0G4Ug@mail.gmail.com>
<aSTNXyXnr9HYsLo6@nathan>
<CA+Tgmob6knHwEbQv11n_Yy0GyFzPgjhC33LroWso0prt7hCksg@mail.gmail.com>
<aSXQOAZuA4rX9ooU@nathan>
<CA+TgmobGYDczmVa-UDGPgcyN=63PJzzyQ9ZCofou4VYH8TVLSQ@mail.gmail.com>
On Tue, Nov 25, 2025 at 11:25:09AM -0500, Robert Haas wrote:
> The downside is that then we have to rely on PG_CATCH() to make things
> whole. I am not sure that there's any problem with that, but I'm also
> not sure that there isn't. The timing of PG_CATCH() block execution
> often creates bugs, because it runs before (sub)transaction abort.
> That means that there's a real risk that you try to acquire an LWLock
> you already hold, for example. It's a lot easier to be confident that
> cleanup actions will reliably succeed when they run inside the
> transaction abort path that knows the order in which various resources
> should be released. Generally, I think it's PG_CATCH() is fine if
> you're releasing a resource that is decoupled from everything else,
> like using a third-party library's free function to free memory
> allocated by that library. But if you're releasing PostgreSQL
> resources that are layered on top of other PostgreSQL resources, like
> a DSA that depends on DSM and LWLock, I think it's a lot more
> difficult to be certain that you aren't going to end up trying to
> release the same stuff multiple times or in the wrong order. I'm not
> saying you can't make it work, but I've banged my head on this
> particular doorframe enough times that my reflex is to duck.
I gave your idea a try, and I like the result a lot. IMHO it makes the
code much easier to reason about.
--
nathan
Attachments:
v3-0001-Revert-Teach-DSM-registry-to-ERROR-if-attaching-t.patch (text/plain, 0B) download
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: pgsql-committers@postgresql.org
Cc: nathandbossart@gmail.com, robertmhaas@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: pgsql: Teach DSM registry to ERROR if attaching to an uninitialized ent
In-Reply-To: <aSXrPqV3Bcm2HLV4@nathan>
* 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