The prisma dev local Postgres shares one session across connections, so Bun prepared statements collide after a restart (42P05)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript
- Domain
- databases
Research direction
Start by reading the reproduction in the issue and tracing startPrismaDevServer and the socket connection handling in @prisma/dev 0.25.2. Reproduce the two-client prepared-statement collision, then investigate how the PGlite session is shared or reset when a connection closes. Done means separate or reset session state prevents 42P05 after a client restart, without requiring prepare: false.
Written by the indexing model from the issue text.
Description
Composer 0.40.0, @prisma/dev 0.25.2.
From Composer's own record; not reproduced here. Composer gotchas.md at v0.40.0, lines 616-646, "prisma dev shares one Postgres session across all connections — a restarted Bun.SQL client crash-loops on 42P05":
- Line 618: "Filed upstream: not yet". Line 619: product
prisma dev/@prisma/dev0.25.2 (PGlite). - Lines 623-632, symptom: the second
prisma devrun, or any restart of a service against the same database, crash-loops withPostgresError: prepared statement "P… $0" already exists,errno: "42P05", routine: "StorePreparedStatement", until the emulator holds the service after 5 fast exits. - Line 636, cause:
@prisma/devruns PGlite, a single-session Postgres, behind a socket, so every client connection shares one backend session, includingpg_prepared_statements, and nothing is reset when a connection closes. Bun names prepared statementsP<query text>$<per-connection counter>, so a restarted process's first statement collides with the dead process's. A real Prisma Postgres gives each connection its own session. - Line 638, workaround:
new SQL({ url, max: 1, idleTimeout: 10, prepare: false }), which Composer's ownemail,authandstoragestores use. - Lines 640-644, reproduction:
startPrismaDevServer({ name, persistenceMode: 'stateless' }); opennew SQL({ url, max: 1 }), runcreate table if not exists t (id int), close it; open a second client and run the same statement: 42P05. Withprepare: falseboth succeed.
The prisma.io docs currently carry a workaround for this, to be removed once it is fixed: apps/docs/content/docs/composer/databases.mdx, the paragraph after the rawPostgres() server snippet that starts "Those pool settings matter" and explains prepare: false (on main since October, not changed on this branch). It tells readers to change their client settings because of this prisma dev defect. Remove the prepare: false advice from that paragraph once @prisma/dev gives each connection its own session (or resets session state when a connection closes). Expected: each client connection to the local Postgres gets its own session, as on Prisma Postgres.
Found while writing the Composer docs on prisma.io (prisma/web#8965).
- Dominant language
- TypeScript
- Stars
- 6
- Forks
- 2
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 33
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
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 prisma/composer
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tashfeenahmed/freellmapi#2305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
prime-radiant-inc/evener#8335 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vercel-labs/ui#1921 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
microsoft/monaco-editor#5626 ·
Maintainers usually reply within 1 day