| From: | Matt Carter <Matt(dot)Carter(at)twosigma(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Andres Freund <andres(at)anarazel(dot)de>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
| Subject: | RE: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed |
| Date: | 2026-10-30 17:25:28 |
| Message-ID: | BL3PR08MB7283F6C6651ACC529F00CCDC996D2@BL3PR08MB7283.namprd08.prod.outlook.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
> Tom Lane wrote:
>> So I think what we really need is more like the attached. This passes
>> our own test suite, but I wonder if you can exercise it in your own
>> environment.
v1 works here. It applies to 18.3 with line offsets and builds without warnings. These are bytes per connection still allocated after warm-up (450 connections), against the same server (gss auth + SSL, MIT krb5 1.20.1):
18.3 unpatched 17844
v1, defaults 94
v1, gssencmode=disable 15
v1, gssdelegation=1 45
v1, gssdelegation=1 gssencmode=disable 46
A 3,000-connection run with defaults has a least-squares slope of 13.5 bytes/connection after warm-up. libpq 13.11 measures 17.5 on the same server, so v1 is at or below pre-16 behavior. Every connection authenticated with GSSAPI.
gdb on gss_init_sec_context() matches your description:
- With gssdelegation unset, the authentication path never calls gss_acquire_cred(). Both gss_init_sec_context() calls get GSS_C_NO_CREDENTIAL with req_flags = GSS_C_MUTUAL_FLAG.
- With gssdelegation=1, there is one gss_acquire_cred() per connection. Both calls share it with req_flags = GSS_C_MUTUAL_FLAG | GSS_C_DELEG_FLAG, and pqDropConnection() releases it.
- With the default gssencmode, the encryption probe's credential is acquired and released inside pqsecure_open_gss(), as before. GSS_C_DELEG_FLAG is set there only when gssdelegation=1.
One limit: this server has gss_accept_delegation = off, so pg_stat_gssapi.credentials_delegated is false with or without the patch. I could confirm that libpq requests delegation, with a forwardable TGT, but not that the server receives the credentials.
Thanks for back-patching to 16. I'm happy to test the back-branch versions too.
Matt
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-10-30 17:36:56 | Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed |
| Previous Message | Tom Lane | 2026-10-30 16:55:00 | Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed |