prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.57k stars 1.54k forks source link

The number of connections in the prisma connection pool suddenly decreased #25013

Closed youxq closed 2 days ago

youxq commented 2 months ago

Bug description

Through the monitoring system, it was found that the connections in the prisma connection pool would be closed suddenly, resulting in a timeout of fetching the connection, prompting Timed out fetching a new connection from the connection pool.

See closing links via netstat

image

The monitoring system prompts that the number of connections suddenly decreases

image image

Query latency p95 is very high: ~30s

image

How to reproduce

Expected behavior

No response

Prisma information

// Add your schema.prisma
generator client {
  provider        = "prisma-client-js"
  output          = "./client"
  previewFeatures = ["metrics"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
export const prismaClient = new PrismaClient({
  log: [
    {
      emit: 'event',
      level: 'query',
    },
    {
      emit: 'stdout',
      level: 'error',
    },
    {
      emit: 'stdout',
      level: 'info',
    },
    {
      emit: 'stdout',
      level: 'warn',
    },
  ],
});

const queryTimeout = process.env.QUERY_TIMEOUT
  ? parseInt(process.env.QUERY_TIMEOUT, 10)
  : 500;
prismaClient.$on('query', e => {
  if (e.duration < queryTimeout) return;
  OrmLogger.info(
    `orm operation exceed time limit(${queryTimeout}ms)`,
    'orm-timeout',
    {
      query: e.query,
      params: e.params,
      duration: e.duration,
    }
  );
});

Environment & setup

Prisma Version

5.12.1
jkomyno commented 2 months ago

Hi, we can't reproduce this issue with the information given so far. Can you please share a self-contained repository with instructions on how to reproduce this? Thanks.

youxq commented 2 months ago

Hi @jkomyno , I've created a self-contained repository that demonstrates the issue: https://github.com/youxq/prisma-connection-test Please follow the instructions in the README.md to reproduce the issue. Let me know if you need any further assistance.

Thank you!