Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMsLD-00000002FPD-1Zl1 for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 19:32:43 +0000 Received: from localhost ([127.0.0.1]:58880 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMsLB-0000000Bsjd-32qV for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 19:32:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:40094) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMsLB-0000000BsjV-1yS4 for pgsql-bugs@lists.postgresql.org; Fri, 30 Oct 2026 19:32:41 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMsL9-00000001kHJ-3Kg7 for pgsql-bugs@lists.postgresql.org; Fri, 30 Oct 2026 19:32:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 69UJWTAx2744648; Fri, 30 Oct 2026 15:32:29 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 sss.pgh.pa.us 69UJWTAx2744648 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sss.pgh.pa.us; s=default; t=1793388749; bh=RNg+QXzY7KwnahjfKQPAw1eCRNuI5FckYvbn2zjngxw=; h=From:To:cc:Subject:In-reply-to:References:Date:From; b=LOgz/sjfuZxXxo60VuQaQA/VpkA3Ql3DaH95zWOFIpjIt7Lz4Or3Z3XVS/UgIFpYn znTJ9vZyrlmcmHerb56FUp05QH+d2CftEGf9gOdj1jG403ABRWRiRyfRrwMJgnC1Lq oU6nB9tyGBLa81taapOFW+D8rUZu+l8UK9152RnE= From: Tom Lane To: Jacob Champion cc: Matt Carter , Andres Freund , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed In-reply-to: References: <19411-0440c8897a04b638@postgresql.org> <1702505.1771347709@sss.pgh.pa.us> <1881734.1771354069@sss.pgh.pa.us> <6xylkfh6idnx7ujhfhyoxku3v67ygoeve4yt7z2ytc65vzwvcv@z2sj5jnamhbe> <2114661.1793306838@sss.pgh.pa.us> <2601836.1793379300@sss.pgh.pa.us> Comments: In-reply-to Jacob Champion message dated "Fri, 30 Oct 2026 12:00:07 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2744646.1793388749.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 30 Oct 2026 15:32:29 -0400 Message-ID: <2744647.1793388749@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jacob Champion writes: > On Fri, Oct 30, 2026 at 9:55 AM Tom Lane 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