pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jacob Champion <jacob.champion@enterprisedb.com>
Cc: Matt Carter <Matt.Carter@twosigma.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed
Date: Fri, 30 Oct 2026 15:32:29 -0400
Message-ID: <2744647.1793388749@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOYmi+=fdEq0VMx0Rqn=5C06wLdZ-h_5_xR2eWHFGv1O_Hg0QQ@mail.gmail.com>
References: <19411-0440c8897a04b638@postgresql.org>
	<1702505.1771347709@sss.pgh.pa.us>
	<BL3PR08MB728301C87997AF17C743633A996DA@BL3PR08MB7283.namprd08.prod.outlook.com>
	<1881734.1771354069@sss.pgh.pa.us>
	<6xylkfh6idnx7ujhfhyoxku3v67ygoeve4yt7z2ytc65vzwvcv@z2sj5jnamhbe>
	<BL3PR08MB72830323C3ED904202F002E0996E2@BL3PR08MB7283.namprd08.prod.outlook.com>
	<2114661.1793306838@sss.pgh.pa.us>
	<BL3PR08MB728371A661250E2282D5FD0E996E2@BL3PR08MB7283.namprd08.prod.outlook.com>
	<2601836.1793379300@sss.pgh.pa.us>
	<CAOYmi+=fdEq0VMx0Rqn=5C06wLdZ-h_5_xR2eWHFGv1O_Hg0QQ@mail.gmail.com>

Jacob Champion <jacob.champion@enterprisedb.com> writes:
> On Fri, Oct 30, 2026 at 9:55 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> /* Only try to acquire credentials if GSS delegation isn't disabled. */
>> -     if (!pg_GSS_have_cred_cache(&conn->gcred))
>> -         conn->gcred = GSS_C_NO_CREDENTIAL;
>> -
>> if (conn->gssdelegation && conn->gssdelegation[0] == '1')
>> -         gss_flags |= GSS_C_DELEG_FLAG;
>> +     {
>> +         if (conn->gcred == GSS_C_NO_CREDENTIAL)
>> +             conn->gcred = pg_GSS_get_cred_cache();
>> +         if (conn->gcred != GSS_C_NO_CREDENTIAL)
>> +             gss_flags |= GSS_C_DELEG_FLAG;
>> +     }

> This might be equivalent logic, but I'm not sure.

You're right, it's intentionally not equivalent logic.

> The current code
> always requests delegation if conn->gssdelegation is true (so if
> pg_GSS_get_cred_cache()/gss_acquire_cred() fail, then delegation will
> still be attempted with GSS_C_NO_CREDENTIAL). The new code requests
> delegation only if gss_acquire_cred() succeeds -- if that fails but
> the later GSS_C_NO_CREDENTIAL attempt succeeds for some weird
> GSS-specific reason, shouldn't we still try to delegate as directed?

How can delegation succeed if there's nothing to delegate?  Also,
the equivalent stanza in pqsecure_open_gss (fe-secure-gssapi.c,
lines 641-656 in master) behaves this way.  I'm much more prepared
to believe that pqsecure_open_gss's behavior is intentional; for
one thing because it matches its comments, which pg_GSS_continue
didn't.

> Are there any delegation cases where we were actually expecting to
> overwrite the previous, valid, credentials?

Doubt it.  There is nothing different about what a repeat call
to pg_GSS_get_cred_cache will do, so I'd expect it to fetch
credentials that are exactly like the old ones, modulo perhaps
a slightly newer expiration time.

> I deleted
> pg_GSS_continue's pg_GSS_have_cred_cache() call entirely, and the
> tests still passed on my machine, which makes me worried that maybe
> there's an edge case that was never recorded. (Alternatively, maybe
> the call is completely unnecessary.)

I wondered about that too.  I tried running the src/test/kerberos
tests with --enable-coverage, and found that they reach every call
of pg_GSS_get_cred_cache *except* the one in pqsecure_open_gss ---
but that's because we already have credentials there, as evidenced by
the fact that the "gss_flags |= GSS_C_DELEG_FLAG" line is reached.
So we do seem to need pg_GSS_continue's call.

Also, if you look at 6633cfb21, this whole stanza in pg_GSS_continue
was introduced then; before that we never passed credentials nor
GSS_C_DELEG_FLAG to that call of gss_init_sec_context, or the other
one either.  So I have to think that's the intended behavior in
non-delegation mode.  In any case, it does not seem to make sense
to be passing different parameters to successive calls of
gss_init_sec_context.

But I'm mostly unfamiliar with the details of GSS, so it's possible
I'm all wet here.

			regards, tom lane






view thread (17+ messages)  latest in thread

Message-ID: <2744647.1793388749@sss.pgh.pa.us>
Permalink:  ../2744647.1793388749@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2744647.1793388749@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jacob.champion@enterprisedb.com, Matt.Carter@twosigma.com, andres@anarazel.de
  Subject: Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed
  In-Reply-To: <2744647.1793388749@sss.pgh.pa.us>
  References: <19411-0440c8897a04b638@postgresql.org> <1702505.1771347709@sss.pgh.pa.us> <BL3PR08MB728301C87997AF17C743633A996DA@BL3PR08MB7283.namprd08.prod.outlook.com> <1881734.1771354069@sss.pgh.pa.us> <6xylkfh6idnx7ujhfhyoxku3v67ygoeve4yt7z2ytc65vzwvcv@z2sj5jnamhbe> <BL3PR08MB72830323C3ED904202F002E0996E2@BL3PR08MB7283.namprd08.prod.outlook.com> <2114661.1793306838@sss.pgh.pa.us> <BL3PR08MB728371A661250E2282D5FD0E996E2@BL3PR08MB7283.namprd08.prod.outlook.com> <2601836.1793379300@sss.pgh.pa.us> <CAOYmi+=fdEq0VMx0Rqn=5C06wLdZ-h_5_xR2eWHFGv1O_Hg0QQ@mail.gmail.com> <2744647.1793388749@sss.pgh.pa.us>

* 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