Skip to content

[NOT A DRIVER BUG] Hyperdrive: "prepared statement already exists" with prepared statements #154

Closed as not planned

Description

@okomarov

Through Cloudflare Hyperdrive, queries can fail with prepared statement "..." already exists (porsager#960). Cloudflare's Hyperdrive guide for postgres.js recommends prepare: true and max: 5, and warns that prepare: false can hang or fail intermittently with Hyperdrive's transaction pooling.

Plan (sub-issue of #15): once the Cloudflare edge Preview workflow (workerd-edge, PR #151) is green, bind a Hyperdrive config in front of its Neon database in previews, and add a hyperdrive scenario that runs prepare: true, max: 5 workloads repeatedly on both builds. Either it reproduces the error, which then gets a fix and a test, or about 100 clean rounds become the evidence for documenting Hyperdrive as supported. Hyperdrive is included in the Workers Free plan (100,000 queries a day).

Activity

  1. added
    bug
    area: runtimes
    upstream
    on Oct 18, 2026
  2. moved this to Next in Roadmapon Oct 18, 2026
  3. changed the title [-]Hyperdrive: "prepared statement already exists" with prepared statements[/-] [+][NOT A DRIVER BUG] Hyperdrive: "prepared statement already exists" with prepared statements[/+] on Oct 19, 2026
  4. okomarov commented on Oct 19, 2026

    @okomarov
    Author

    Not a driver bug. Hyperdrive with prepared statements works when it points at the database. It fails when it sits in front of a transaction-mode pooler such as Supabase's Supavisor on port 6543, which porsager#960 most likely used (env.DB_SUPABASE).

    Evidence from the edge tier (landed in 063909d, #158). Each round runs 50 concurrent insert-and-select pairs with max: 5 and prepare: true, on both builds at compatibility dates 2025-01-01 and 2026-10-12.

    Hyperdrive in front of Result
    Neon, direct 289 rounds passed in a 60-round dispatch run (39229088257), no prepared-statement error
    Neon, PgBouncer pooler passed in the same run
    Supabase, direct connection, verify-full against Supabase's CA every round passed
    Supabase, Supavisor transaction mode every round failed: prepared statement does not exist (26000), CONNECTION_CLOSED, timeouts (run 39234865111)

    Supavisor's transaction mode fails the same way without Hyperdrive: locally, five connections with prepare: true give does not exist, and queued queries stall. The report's "already exists" is the other side of the same mismatch: named statements end up split across server connections by two layers of transaction pooling.

    The vendors document this:

    Fix: point Hyperdrive at the database itself, keep prepare: true, and use max: 5. docs/api.md (Cloudflare Workers support → Hyperdrive) now says this. CI keeps covering Hyperdrive in front of Neon direct, Neon pooled and Supabase direct on every change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: runtimesbugupstream

    Type

    No type

    Projects

    • Status
      Next

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions