electric-sql / electric-sql/pglite
pglite-server -m multiplexer: "invalid frontend message type" with a Postgres-wire client in WebContainers
- Dominant language
- TypeScript
- Stars
- 16k
- Forks
- 442
- Avg merge
- 20h 19m
- Merged PRs (30d)
- 7
Description
### Summary
Running the `pglite-server` CLI with the multiplexer (`-m`) inside a **WebContainers (StackBlitz)** browser environment, a single `node-postgres` `Client` connection fails with `invalid frontend message type 47` on the server, and the client errors out (`Command exited with code 1`). The identical setup runs correctly on **native Node**.
### Environment
- `@electric-sql/pglite` `0.5.3`, `@electric-sql/pglite-socket` `0.2.6`
- Runtime: WebContainers (StackBlitz), in-browser, Node `v22.x`
- Server: `npx pglite-server -m 10 -h 127.0.0.1 -p 5432` (default in-memory `memory://`)
- Client: `node-postgres` (`pg`) `8.13.1`
### What we see
```
Initializing PGLite with database: memory://
Imported extension: pgcrypto
PGLiteSocketServer listening on {"port":5432,"host":"127.0.0.1"}
Client connected from 127.0.0.1:1
Client connected from 127.0.0.1:1
invalid frontend message type 47
Command exited with code 1
```
The client is a plain `new Client({ connectionString: 'postgres://postgres:postgres@127.0.0.1:5432/postgres' })` running a sequential migration (`BEGIN` + a few `CREATE TABLE`/`INSERT`). `47` is `0x2F`.
### Ruled out
- **Not SSL** — the client sets no `ssl` option and the DSN has no `sslmode`, so `pg` never sends an `SSLRequest`.
- **Not client-side concurrency** — it's a single `Client` (not a `Pool`), connecting once and querying sequentially.
- **Works on native Node** — the same migration against `pglite-server -m` on a normal Node host succeeds. So this looks specific to the WebContainers network stack interacting with the multiplexer's wire framing.
### Repro sketch
1. In a WebContainers/StackBlitz project: `npx pglite-server -m 10 -h 127.0.0.1 -p 5432 --run "node client.mjs"`
2. `client.mjs`: connect a single `pg.Client` to `127.0.0.1:5432`, `await client.query('select 1')`.
3. Observe `invalid frontend message type 47` on the server.
Happy to assemble a minimal StackBlitz repro if it would help. Thanks for pglite + pglite-socket — the in-browser Postgres-wire server is exactly what we needed.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the pglite-server CLI in multiplexer mode and reproduce the provided single-client migration in WebContainers, then compare its wire framing with native Node. Trace the frontend message handling in the multiplexer and pglite-socket path; done means the same `pg.Client` connection and `select 1` migration work in WebContainers without the invalid message error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, postgres, typescript
- Domain
- databases, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100