Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG]: windowed live.query leaks its total-count prepared statement on unsubscribe

Closed Beginner friendly
#1,111 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@askalf is already working on this.

Since Sep 14, 2026.

  • #1108 by @askalf — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
92/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, typescript
Domain
databases, testing

Research direction

Start in packages/pglite/src/live/index.ts and run the windowed-query teardown test in packages/pglite/tests/live.test.ts, named "deallocates all prepared statements for a windowed query on unsubscribe." Done means unsubscribing removes both prepared statements and the test passes with no remaining live_query_* entries.

Written by the indexing model from the issue text.

Description

Describe the bug

A windowed live.query (one given both offset and limit) prepares two statements, live_query_<id>_get(int, int) and live_query_<id>_get_total_count, but unsubscribe only runs DEALLOCATE live_query_<id>_get. The count statement survives every teardown while its backing view live_query_<id>_view is dropped, so it is left permanently dangling and one more accumulates per subscribe/unsubscribe cycle for the lifetime of the database.

To Reproduce

import { PGlite } from '@electric-sql/pglite'
import { live } from '@electric-sql/pglite/live'

const pg = await PGlite.create({ extensions: { live } })
await pg.exec(`CREATE TABLE t (id serial PRIMARY KEY); INSERT INTO t DEFAULT VALUES;`)

const { unsubscribe } = await pg.live.query({
  query: 'SELECT * FROM t',
  offset: 0,
  limit: 10,
  callback: () => {},
})

const before = await pg.query(`SELECT name FROM pg_prepared_statements WHERE name LIKE 'live_query_%'`)
// before.rows: live_query_<id>_get and live_query_<id>_get_total_count

await unsubscribe()

const after = await pg.query(`SELECT name FROM pg_prepared_statements WHERE name LIKE 'live_query_%'`)
// expected: []
// actual:   [{ name: 'live_query_<id>_get_total_count' }]

The survivor is dangling, not merely leaked: EXECUTE live_query_<id>_get_total_count after unsubscribe fails because the view it selects from is gone. A non-windowed query (no offset/limit) tears down cleanly, since it never prepares the count statement.

The executable form of this is the test added in #1108 (packages/pglite/tests/live.test.ts, "deallocates all prepared statements for a windowed query on unsubscribe"), which fails on main with expected [ Array(1) ] to deeply equal [] and passes with the fix.

Logs

error: relation "live_query_<id>_view" does not exist

(from EXECUTE live_query_<id>_get_total_count after unsubscribe)

Details

  • PGlite version: 0.5.8 (main at the time of filing)
  • using any extensions? which ones? live
  • OS version: Linux x64
  • node, bun, deno or browser version: Node 24

Additional context

Cause is in packages/pglite/src/live/index.ts: the unsubscribe teardown deallocates live_query_<id>_get unconditionally but never the total-count statement, even though the prepare path guards its creation on the same isWindowed flag. Mirroring that guard in the teardown is the fix in #1108.

Dominant language
TypeScript
Stars
16.1k
Forks
447
Avg merge
5d 14h
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from electric-sql/pglite

All issues in electric-sql/pglite

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.