too many connections: Too many connections to one database
The database hit its concurrent connection limit: pools opening unbounded connections per request are the usual cause.
- Error
too many connections- Category
- Remote server and Hrana errors
What it means
A remote database can only carry so many simultaneous connections, and the server refuses new ones past that point. Each serverless request that creates a fresh client counts as a new connection, so a function-per-request setup can blow through the limit even at modest traffic. This is a connection-count limit, distinct from the 429 request-rate limit, though both come from unbounded client fan-out.
Common causes
- Creating a new client per request instead of reusing one.
- A connection pool sized far above what the database plan allows.
- Connections left open by interactive transactions that never committed or rolled back.
- Many serverless instances each holding their own pool.
Find the cause
Count concurrent clients: grep your code for `createClient` calls. One per request path is the bug. Then estimate concurrency: serverless platforms scale to many instances, each with its own pool, so multiply pool size by instance count and compare with the point where the refusals started. If connections climb over time and never fall, look for transactions opened without commit or rollback.
How to fix it
-
Create the client once at module scope and reuse it:
// module scope, not per request export const db = createClient({ url: process.env.LIBSQL_URL, authToken: process.env.LIBSQL_TOKEN }); -
Shrink pool sizes to something the plan can carry:
// generic pool config { max: 5 } -
Always close or roll back interactive transactions, including on error:
const tx = await db.transaction('write'); try { await tx.execute(sql); await tx.commit(); } catch (e) { await tx.rollback(); throw e; }
Other ways to handle it
HTTP-over-request connections (/v2/pipeline per request, no persistent session) sidestep the persistent-connection count at the cost of per-request latency. Batching statements also reduces the connection time per unit of work.
Reproduce it safely
Honest repro needs a real database and opening more connections than the plan allows, which can disturb other users, so I would use a dedicated test database: open a loop of `createClient(...)` connections without closing them until the server refuses. Exact refusal message varies by client; the observable is new connections failing while existing ones still work. `turso dev` has no such limit.
Questions
Should I create a new @libsql/client for every request?
No. Create it once at module scope and reuse it; each new client is a new connection, and a fresh client per request in a serverless function multiplies into hundreds of connections under load.
How many concurrent requests does @libsql/client make at once?
Up to 20 by default; the concurrency config option raises or removes the limit. Keep it aligned with what the database tolerates instead of disabling it.
How is this different from a 429?
429 throttles request rate; this refuses new connections while existing ones still work. Both trace back to unbounded fan-out: per-request clients and pools sized for a different database.
Related errors
429 Too Many Requestsrequest rate limit hitconnection reset / interruptedConnection reset or droppedSQLITE_BUSYSQLITE_BUSY: the database is busy
More remote server and hrana errors errors
404 Not Found404 Not Found: unknown database or endpointTransaction timed-outinteractive transaction abortedError in remote responseError in remote response500 Internal Server Errorserver failed on a valid request402 Payment Required402 Payment Required409 Conflict409 Conflictdatabase not foundturso CLI: database not found
The code and message text are from the libSQL / Turso documentation. Browse the full libSQL error list or search every database error.
Work on libSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for libSQL and the other databases you use.
Text and data on this page: CC BY 4.0, credit SQLly (sqlly.app). Code and SQL snippets: MIT. License details Quoted error message text belongs to its database vendor. View as Markdown