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

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state