[PATCH] Fix leaked hash scans in pg_listening_channels()

Started by Joel Jacobson4 days ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t254268
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 22, 2026 at 06:18 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t254268_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t254268_1 && git checkout t254268_1

Patchset v1 (message #1) is on t254268_1

Jump to latest
#1Joel Jacobson
joel@compiler.org

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

Attachments:

t254268_1
0001-Fix-leaked-hash-scans-in-pg_listening_channels.patchapplication/octet-stream; name="=?UTF-8?Q?0001-Fix-leaked-hash-scans-in-pg=5Flistening=5Fchannels.patch?="Download+32-36
#2Sho Ito
i.sho.0628@gmail.com
In reply to: Joel Jacobson (#1)
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()

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.

The materialization approach follows the SRF guidance in `funcapi.h` and
looks good to me.

Thanks,
Sho

--
=======================================
*Sho Ito (Sean)*

E-mail: i.sho.0628@gmail.com
LinkedIn: *https://www.linkedin.com/in/sho-ito-0628/
<https://www.linkedin.com/in/sho-ito-0628/&gt;*
GitHub: https://github.com/sean0628/
=======================================

#3Joel Jacobson
joel@compiler.org
In reply to: Sho Ito (#2)
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()

On Wed, Oct 21, 2026, at 09:19, Sho Ito wrote:

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.

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

#4Sho Ito
i.sho.0628@gmail.com
In reply to: Joel Jacobson (#3)
Re: [PATCH] Fix leaked hash scans in pg_listening_channels()

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
LinkedIn: *https://www.linkedin.com/in/sho-ito-0628/
<https://www.linkedin.com/in/sho-ito-0628/&gt;*
GitHub: https://github.com/sean0628/
=======================================