[BUG]: Parameter count higher than 16bit gets dropped silently
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript, wasm
- Domain
- databases
Research direction
Start in packages/pg-protocol/src/buffer-reader.ts at int16() (getInt16 vs unsigned 16-bit protocol counts) and how parser.ts uses it for ParameterDescription. Reproduce with the multi-row insert of 32768 parameters in the issue; n=32767 should still work. Done when that insert reports the right affectedRows, later queries still work, and the instance is not left unusable.
Written by the indexing model from the issue text.
Description
Describe the bug
A query binding more than 32767 parameters is silently dropped. query() resolves
with affectedRows: 0 and rows: [], no error is thrown, and the instance is left
unusable, every later query resolves with empty results too.
The real limit is 65535 parameters (Postgres's own limit); 32768–65535 work fine
against a real Postgres server through pg. PGlite fails at 32768.
To Reproduce
import { PGlite } from "@electric-sql/pglite";
const db = await PGlite.create();
await db.exec('create table "t" ("a" text)');
const n = 32768;
const tuples = Array.from({ length: n }, (_, i) => `($${i + 1}::text)`);
const values = Array.from({ length: n }, (_, i) => `v${i}`);
// resolves, no throw
const result = await db.query(`insert into "t" ("a") values ${tuples.join(", ")}`, values);
console.log(result.affectedRows); // 0, expected 32768
// the instance is now dead: resolves with [] instead of [ { one: 1 } ]
console.log(await db.query("select 1 as one"));
n = 32767 works; n = 32768 is the first failure. 32 parameters per row means this
is a ~1024-row multi-row insert, which is easy to reach for bulk inserts.
Logs
n=32767 -> affectedRows=32767 | next: [ { one: 1 } ]
n=32768 -> affectedRows=0 | next: []
n=32769 -> affectedRows=0 | next: []
With new PGlite({ debug: 5 }) the failing statement produces no Postgres ERROR
or FATAL in the log at all.
Details
- PGlite version: 0.5.8 (also present on main, d9eadc63)
- Extensions: none
- OS: Fedora Linux 44 (Workstation), x86_64
- Node: v24.18.0
Additional context
This fix may contain hallucinations, but I think it could be correct:
Fix: int16() in packages/pg-protocol/src/buffer-reader.ts should use getUint16()
instead of getInt16(), since the protocol's 16-bit counts are unsigned. parser.ts
reads the ParameterDescription count with it and new Array(-32768) then throws, which
is what kills the instance.
- Dominant language
- TypeScript
- Stars
- 16.1k
- Forks
- 447
- PR merge metrics
- No merged PRs in 30d
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from electric-sql/pglite
-
Feature request: Nitro 3 support (`unwasm` export condition)Possibly taken @pi0x claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
electric-sql/pglite#1120 · 2 comments ·
-
[BUG]: windowed live.query leaks its total-count prepared statement on unsubscribePossibly taken @askalf claimed this 24 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
electric-sql/pglite#1111 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
electric-sql/pglite#1048 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 72/100
electric-sql/pglite#1122 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
electric-sql/pglite#1116 ·
All issues in electric-sql/pglite
Similar issues
-
Flaky: mongodb-memory-server 'Port already in use' when another process starts a mongod concurrentlyOpenarea:testing bug effort:S priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
lens:agent lens:process process
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
thebristolsound/birdbrain#1772 ·
Maintainers usually reply within 1 day
-
bug priority:low ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/data-liberation-agent#685 ·
Maintainers usually reply within 1 day
-
Business
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day