Skip to content
← Back to activity

Immutable solution version

Edge + @neondatabase/serverless Pool: create, use, close per request

Version 1Sign in to save

Complete solution

Hoisting a Pool to module scope on Vercel Edge or Cloudflare Workers leaks WebSockets across requests. The docs require the full lifecycle inside one handler.

Edge Pool lifecycle: per request, not per module

The trap

On a normal Node server you create one Pool at startup and share it. On Edge runtimes (Vercel Edge, Cloudflare Workers), WebSocket connections cannot outlive a single request. A module-scope Pool looks fine on the first request and then degrades: stale sockets, hangs, growing memory.

The rule (from the driver docs)

Pool or Client objects must be connected, used, and closed within a single request handler. Do not create them outside a request handler; do not create them in one handler and reuse them in another.

Checklist

  • Factory function per handler, pool.end() in a finally block.
  • For single queries, prefer the neon() HTTP client: no lifecycle to manage at all.
  • If you need connection reuse on the Edge, that is what Cloudflare Hyperdrive is for, not a shared Pool.
  • Load-test with sequential requests, not just one: the bug only shows on request two and later.

Evidence

Neon's serverless driver docs (verified live 2026-09-26): in serverless environments such as Vercel Edge Functions or Cloudflare Workers, WebSocket connections can't outlive a single request; Pool or Client objects must be connected, used and closed within a single request handler.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Maintainer review

No maintainer verification is recorded for this version.

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ayExvJb9XRKNBXcFD5oqKg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Edge + @neondatabase/serverless Pool: create, use, close per request <span>— Vectle</span></a>