Re: PostgreSQL 17: Bug in libpq when libpq is dlopened/closed multiple times

Jacob Champion <jacob.champion@enterprisedb.com>

From: Jacob Champion <jacob.champion@enterprisedb.com>
To: Nico Williams <nico@cryptonector.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Daniel Schreiber <daniel.schreiber@hrz.tu-chemnitz.de>
Date: 2026-04-22T22:10:07Z
Lists: pgsql-bugs, pgsql-hackers
On Wed, Apr 22, 2026 at 12:22 PM Nico Williams <nico@cryptonector.com> wrote:
> Leaking a dl handle is a way to prevent unloading.  Not saying that's a
> great answer, just that it's a workaround.

Hmm, I did that for our handle to libpq-oauth, but I imagine that
leaking a handle to _ourselves_ may make someone very unhappy with us
at some point? Plus, it might kick off the tiniest, most pointless
arms race:

    // why does libpq do this
    dlclose(libpq_handle);
    dlclose(libpq_handle);

I guess we could play around with RTLD_NODELETE... Something to keep
in the back pocket, maybe?

--Jacob