Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa Adatta ai principianti
#1,111 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@askalf ci sta già lavorando.

Dal 14/9/2026.

  • #1108 di @askalf — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
92/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, typescript
Ambito
databases, testing

Direzione di ricerca

Inizia da packages/pglite/src/live/index.ts ed esegui il test di teardown della query windowed in packages/pglite/tests/live.test.ts, denominato "deallocates all prepared statements for a windowed query on unsubscribe". Il lavoro è completato quando la disiscrizione rimuove entrambe le istruzioni preparate e il test passa senza voci live_query_* residue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
16.1k
Fork
456
Merge medio
1g 7h
PR unite (30g)
15

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di electric-sql/pglite

Tutte le issue di electric-sql/pglite

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.