drizzle-team / drizzle-team/drizzle-orm

[BUG]: Too many connections

Open
#2,179 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.30.88

### What version of `drizzle-kit` are you using?

0.20.14

### Describe the Bug

when using dirzzle i'm getting the following error

⨯ Internal error: Error: Too many connections
at PromisePool.query (./node_modules/mysql2/promise.js:356:22)
at MySql2PreparedQuery.execute (./node_modules/drizzle-orm/mysql2/session.js:58:33)
at MySqlSelectBase.execute (./node_modules/drizzle-orm/mysql-core/query-builders/select.js:693:27)
at MySqlSelectBase.then (./node_modules/drizzle-orm/query-promise.js:26:17)
digest: "991646260"

this my db connection code
import { drizzle } from "drizzle-orm/mysql2";
import * as schema from "./schema/schema";
import mysql from "mysql2/promise";

const connection = mysql.createPool({
host: process.env.HOST as string,
user: process.env.USER as string,
password: process.env.PASSWORD as string,
database: process.env.DATABASE as string,
port: parseInt(process.env.DB_PORT as string),
});

export const db = drizzle(connection, { schema, mode: "default", logger: true });

### Expected behavior

Instead of creating a new connection it's better to do something like how prisma does

import { PrismaClient } from '@prisma/client'

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }

export const prisma =
globalForPrisma.prisma || new PrismaClient()

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma

### Environment & setup

HOST=localhost
USER=root
PASSWORD=localmysql
DATABASE=drizzle
PORT=3306

Contributor guide

Open the contributing guide

Research direction

Reproduce the error with the provided drizzle-orm 0.30.88 and drizzle-kit 0.20.14 setup, then start from the mysql2 pool usage shown in node_modules/mysql2/promise.js and drizzle-orm/mysql2/session.js. Compare the connection lifecycle with the expected Prisma-style reuse and verify that repeated queries no longer exhaust the database connection limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, typescript
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.