[BUG]: drizzle-orm/planetscale-serverless reuses connection, leading to inconsistent issues
Problem
What version of `drizzle-orm` are you using? 0.29..3 What version of `drizzle-kit` are you using? 0.20.9 Describe the Bug When using planetscale with drizzle, the planetscale connection is reused for subsequent queries to the db. This is an incorrect usage of the planetscale/database driver and can lead to issues with queries/returns in parallel transactions/queries. see: https://github.com/planetscale/database-js/issues/139 & https://github.com/mattrobenolt/ps-http-sim/issues/1 The issue was highlighted here: https://github.com/mattrobenolt/ps-http-sim/issues/7#issuecomment-1864636196 In my local testing: when using the planetscale/database driver directly, for each query a new connections+session is created when using via drizzle-orm/planetscale-serverless, a single connection is created and reused for each subsequent query until the connection is closed by the PS server how this was discovered: A planetscale simulator was created by @mattrobenolt who also works at PS. the logs and errors returned by the simulator highlighted this discussion here: https://github.com/mattrobenolt/ps-http-sim/issues/7 how to test/replicate: use the planetscale simulator docker compose example and monitor logs: https://github.com/mattrobenolt/ps-http-sim run multiple drizzle queries in quick succession check docker logs for how many sessionIds were created Run the same queries directly using `@planetscale/database` recheck docker logs and count sessionIds example log [code block] E
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: [BUG]: drizzle-orm/planetscale-serverless reuses connection, leading to inconsistent issues
I'll articulate when I'm at a computer. But it's not a new connection per query. It's a new connection for anything in parallel or per session. This should map identically to how usage of a typical MySQL connection works. You must reuse the same connection for transactions and other state. But because of the same reason, a single connection cannot be used safely in parallel because of state and tr
Trust Score
1 verification
- 1
I'll articulate when I'm at a computer. But it's not a new connection per query.
I'll articulate when I'm at a computer. But it's not a new connection per query. It's a new connection for anything in parallel or per session. This should map identically to how usage of a typical MySQL connection works. You must reuse the same connection for transactions and other state. But because of the same reason, a single connection cannot be used safely in parallel because of state and transactional safety. The behavior becomes unpredictable and undefined.
Validation
Resolved in drizzle-team/drizzle-orm GitHub issue #1743. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep