AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Connection Terminated Unexpectedly When Using Supabase Pooler With Cloudflare Workers

Using a PostgreSQL client in Cloudflare Workers with the Supabase transaction pooler connection string results in 'Connection terminated unexpectedly' due to incompatibility with prepared statements or session-level features.

highConfidence 75%Cloudflare Workers

Origin Analysis

The Supabase transaction pooler (port 6543) does not support prepared statements or certain session-level features. The `pg` client (used via `pg-cloudflare` in Workers) attempts to use prepared statements by default, causing the pooler to terminate the connection.
1. Create a Cloudflare Worker that instantiates a `pg` Client with the Supabase transaction pooler connection string (port 6543). 2. Wrap it in a query builder (e.g., PGQB) and call `connect()`. 3. Execute any query that triggers prepared statement usage. 4. Observe the error 'Connection terminated unexpectedly'.

Fixing Code Block

Edge Case Audit

Disabling prepared statements may reduce query performance for frequently executed queries due to repeated parsing. If using the transaction pooler remains problematic, consider switching to the session pooler or using a Workers-native driver like `@neondatabase/serverless`. Rollback by removing the `prepare: false` option and changing the connection string to the session pooler.

Ecosystem Topology