[PATCH] Fix leaked hash scans in pg_listening_channels()
[PATCH] Fix leaked hash scans in pg_listening_channels()
Hi hackers, I found a hash scan leak in pg_listening_channels(), introduced by 282b1cde9d. LISTEN ch; SELECT pg_listening_channels() LIMIT 1; The SELECT emits a leak warning in the server logs. Repeated early exits can exhaust the hash scan limit and cause a server crash. Attached patch uses InitMaterializedSRF() to complete the scan before returning rows, following 257c8231bf. /Joel
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()
От:
Sho Ito <i.sho.0628@gmail.com>
Дата:
On Mon, Oct 19, 2026 at 2:42 PM Joel Jacobson <joel@compiler.org> wrote:
Attached patch uses InitMaterializedSRF() to complete the scan
before returning rows, following 257c8231bf.
Hi Joel,
I reviewed the attached patch on master with assertions enabled. Before the fix,
repeated target-list calls under `LIMIT` in one transaction cause
a backend crash with `PANIC: ERRORDATA_STACK_SIZE exceeded`. With the patch,
the same workload completes without warnings or errors.
I reviewed the attached patch on master with assertions enabled. Before the fix,
repeated target-list calls under `LIMIT` in one transaction cause
a backend crash with `PANIC: ERRORDATA_STACK_SIZE exceeded`. With the patch,
the same workload completes without warnings or errors.
The materialization approach follows the SRF guidance in `funcapi.h` and looks good to me.
Thanks,
Sho
Thanks,
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()
От:
"Joel Jacobson" <joel@compiler.org>
Дата:
On Wed, Oct 21, 2026, at 09:19, Sho Ito wrote: > On Mon, Oct 19, 2026 at 2:42 PM Joel Jacobson wrote: >> Attached patch uses InitMaterializedSRF() to complete the scan >> before returning rows, following 257c8231bf. > > Hi Joel, > > I reviewed the attached patch on master with assertions enabled. Before the fix, > repeated target-list calls under `LIMIT` in one transaction cause > a backend crash with `PANIC: ERRORDATA_STACK_SIZE exceeded`. With the patch, > the same workload completes without warnings or errors. > > The materialization approach follows the SRF guidance in `funcapi.h` > and looks good to me. Thanks for review. Here is the commitfest entry: https://commitfest.postgresql.org/patch/7481/ If you think it's Ready for Committer you can update the status there. > > Thanks, > Sho > > -- > ======================================= > *Sho Ito (Sean)* > > E-mail: i.sho.0628@gmail.com > LinkedIn: _https://www.linkedin.com/in/sho-ito-0628/_ > GitHub: https://github.com/sean0628/ > ======================================= -- Kind regards, Joel
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()
От:
Sho Ito <i.sho.0628@gmail.com>
Дата:
On Thu, Oct 22, 2026 at 3:56 AM Joel Jacobson <joel@compiler.org> wrote:
If you think it's Ready for Committer
you can update the status there.
Updated. Thanks!
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()
От:
"Joel Jacobson" <joel@compiler.org>
Дата:
On Thu, Oct 22, 2026, at 16:09, Sho Ito wrote: > On Thu, Oct 22, 2026 at 3:56 AM Joel Jacobson wrote: >> If you think it's Ready for Committer >> you can update the status there. > > Updated. Thanks! Thanks. I noticed that the Windows job failed on cfbot, but it seems unrelated to this patch. It's failing libpq's SSL negotiation test, 005_negotiate_encryption.pl. All 239 core regression tests passed, including async: ok 142 + async 795 ms Above from log archive https://nightly.link/postgres/postgres-cfbot/actions/artifacts/12553603210.zip build/meson-logs/testlog.txt, line 224 /Joel
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Joel Jacobson" writes: > I found a hash scan leak in pg_listening_channels(), introduced by > 282b1cde9d. Good catch. > Attached patch uses InitMaterializedSRF() to complete the scan > before returning rows, following 257c8231bf. I am wondering why you used MAT_SRF_USE_EXPECTED_DESC? AFAICT that's only needed in functions returning "setof record", and with a fixed output type it's usual to just pass flags = 0. regards, tom lane
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I wrote: > I am wondering why you used MAT_SRF_USE_EXPECTED_DESC? Ah, never mind that: I find that if you don't, you get regression=# SELECT pg_listening_channels() ; ERROR: return type must be a row type regression=# \errverbose ERROR: XX000: return type must be a row type LOCATION: InitMaterializedSRF, funcapi.c:109 I question whether this aspect of InitMaterializedSRF is well-designed, but I suppose now is no time to rethink that. regards, tom lane