Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel execution with Promise.all causes P2024 error in version 5.8.0 due to connection limit #22610

Closed
fujita-h opened this issue Jan 10, 2024 · 13 comments · Fixed by prisma/prisma-engines#4641
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. topic: mysql topic: postgresql topic: Timed out fetching a new connection ... from the connection pool
Milestone

Comments

@fujita-h
Copy link

Bug description

In version 5.8.0, when using Promise.all to execute queries in parallel, some queries generate a P2024 error if the number of connection_limit is less than the number of parallel executions.

In version 5.7.1, I got the desired results without any errors.

How to reproduce

see https://github.com/fujita-h/issue-prisma-580

Expected behavior

No response

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}
  // Create test data
  await Promise.all([...Array(10)].map((_, i) => i).map((i) => {
    const id = i + 1;
    const email = `user${i}@example.com`;
    return prisma.user.upsert({
      where: { id },
      create: { id, email },
      update: {},
    })
  }));
  await Promise.all([...Array(10)].map((_, i) => i).map((i) => {
    const id = i + 1;
    const title = `title-${i}`;
    return prisma.post.upsert({
      where: { id },
      create: { id, title, authorId: id },
      update: {},
    })
  }));

  // Query which causes the error on Prisma Client 5.8.0
  const posts = await Promise.all([...Array(10)].map((_, i) => i).map((i) => {
    const id = i + 1;
    return prisma.post.findUnique({
      where: {
        id,
        OR: [
          { author: { id: id } }
        ]
      },
    })
  }));

  console.log(posts);

Environment & setup

  • OS: Ubuntu 22.04
  • Database: MySQL 8.0
  • Node.js version: v20.10.0

Prisma Version

prisma                  : 5.8.0
@prisma/client          : 5.8.0
Computed binaryTarget   : debian-openssl-3.0.x
Operating System        : linux
Architecture            : x64
Node.js                 : v20.10.0
Query Engine (Node-API) : libquery-engine 0a83d8541752d7582de2ebc1ece46519ce72a848 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Schema Engine           : schema-engine-cli 0a83d8541752d7582de2ebc1ece46519ce72a848 (at node_modules/@prisma/engines/schema-engine-debian-openssl-3.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.8.0-37.0a83d8541752d7582de2ebc1ece46519ce72a848
Default Engines Hash    : 0a83d8541752d7582de2ebc1ece46519ce72a848
Studio                  : 0.497.0
@fujita-h fujita-h added the kind/bug A reported bug. label Jan 10, 2024
@jkepps
Copy link

jkepps commented Jan 10, 2024

I'm generally getting a significantly higher number of connection pool timeout errors in 5.8.0 than I was in 5.7.1. I needed to revert back to 5.7.1 for now

@janpio
Copy link
Member

janpio commented Jan 10, 2024

I don't think 5.8.0 really changed anything that could have impact on this. Is this reproducible for you?

@jkepps
Copy link

jkepps commented Jan 10, 2024

In my case I wasn't necessarily using a Promise.all whenever the error was thrown, but it was always the result of a series of findUnique within an Apollo Server resolver. I know that when I return a collection of records, many of my graphql fields have resolvers that will make a call to findUnique, but I would expect those calls to be batched under the hood

@fujita-h
Copy link
Author

This example is not code that will actually be used in production. Of course, there is no need to write code like this to retrieve data from posts, but I did it this way to simplify the problem I was having.

In my use case, the usage was as follows.

const postIds: string[] = await getPostIdsFromOtherSource()

const getPostsInPostIdsOnlyAuthorGroupAorB = await Promise.all(postIds.map((postId)=> {
  const post = await prisma.post.findUnique({
    where: { 
      id: postId, 
      OR: [
        { author: { group: 'A Group' } },
        { author: { group: 'B Group' } },
      ]
    }
  })
})

Of course, this is not a good idea as it will call a large number of queries. There should be a different logic, but a situation occurred where there was no problem with 5.7.1, but a problem occurred with 5.8.0.

As I investigated, I found that it was related to the value of connection_limit and the number of parallels in Promise.all, so I submitted it as an issue.

The important thing here is that when connection_limit is 1, Promise.all cannot parallelize more than one query. The problem does not arise because the number of queries is large.

The point is

  • Calling multiple queries using Promise.all
  • connection_limit is less than the total number of queries executed in Promise.all
  • The where of the query is somewhat complex (in this case, we include OR[]. If there is no OR[] part, there will be no problem.)

@duongdev
Copy link

duongdev commented Jan 11, 2024

Facing this issue too when I made a GraphQL query with nested field resolver. I needed to revert back to 5.7.1

@Jolg42 Jolg42 self-assigned this Jan 11, 2024
@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/regression A reported bug in functionality that used to work before. topic: mysql topic: postgresql topic: Timed out fetching a new connection ... from the connection pool bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jan 11, 2024
@Jolg42 Jolg42 removed their assignment Jan 11, 2024
@Jolg42
Copy link
Contributor

Jolg42 commented Jan 11, 2024

Thanks for the reproduction repository https://github.com/fujita-h/issue-prisma-580 @fujita-h

I could reproduce the following error against a local database and I could identify 5.8.0-dev.7 as the first version where this appeared.

So looking at commits on Prisma engines (prisma/prisma-engines@5.8.0-dev.6...5.8.0-dev.7), the only one that looks suspicious would be from:

feat(query-engine-wasm): vertical slice (#4466)
prisma/prisma-engines#4466

I'll ask my colleagues who worked on that PR to check it and see what they think.

The reproduction

With MySQL (like in your reproduction)

ts-node index.ts 
PrismaClientKnownRequestError: 
Invalid `prisma.post.findUnique()` invocation in
/Users/j42/Repros/issue-prisma-580/index.ts:31:24

  28 // Query which causes the error on Prisma Client 5.8.0
  29 const posts = await Promise.all([...Array(10)].map((_, i) => i).map((i) => {
  30   const id = i + 1;
→ 31   return prisma.post.findUnique(
Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5)
    at si.handleRequestError (/Users/j42/Repros/issue-prisma-580/node_modules/@prisma/client/runtime/library.js:125:6817)
    at si.handleAndLogRequestError (/Users/j42/Repros/issue-prisma-580/node_modules/@prisma/client/runtime/library.js:125:6151)
    at si.request (/Users/j42/Repros/issue-prisma-580/node_modules/@prisma/client/runtime/library.js:125:5859)
    at async l (/Users/j42/Repros/issue-prisma-580/node_modules/@prisma/client/runtime/library.js:130:9805)
    at async Promise.all (index 0)
    at async main (/Users/j42/Repros/issue-prisma-580/index.ts:29:17) {
  code: 'P2024',
  clientVersion: '5.8.0',
  meta: { modelName: 'Post', connection_limit: 5, timeout: 10 }
}

and I also tried PostgreSQL

PrismaClientKnownRequestError: 
Invalid `prisma.post.findUnique()` invocation in
/Users/j42/Repros/issue-prisma-580-pg/index.ts:31:24

  28 // Query which causes the error on Prisma Client 5.8.0
  29 const posts = await Promise.all([...Array(10)].map((_, i) => i).map((i) => {
  30   const id = i + 1;
→ 31   return prisma.post.findUnique(
Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5)
    at si.handleRequestError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:6817)
    at si.handleAndLogRequestError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:6151)
    at si.request (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:5859)
    at async l (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:130:10025)
    at async Promise.all (index 0)
    at async main (/Users/j42/Repros/issue-prisma-580-pg/index.ts:29:17) {
  code: 'P2024',
  clientVersion: '5.8.0-dev.7',
  meta: { modelName: 'Post', connection_limit: 5, timeout: 10 }
}
Full DEBUG logs ``` DEBUG=* ts-node index.ts prisma:tryLoadEnv Environment variables loaded from /Users/j42/Repros/issue-prisma-580-pg/.env +0ms prisma:client checkPlatformCaching:postinstall undefined +0ms prisma:client checkPlatformCaching:ciName undefined +0ms prisma:tryLoadEnv Environment variables loaded from /Users/j42/Repros/issue-prisma-580-pg/.env +2ms prisma:client dirname /Users/j42/Repros/issue-prisma-580-pg/node_modules/.prisma/client +0ms prisma:client relativePath ../../../prisma +0ms prisma:client cwd /Users/j42/Repros/issue-prisma-580-pg/prisma +0ms prisma:client clientVersion 5.8.0-dev.7 +0ms prisma:client:libraryEngine internalSetup +0ms prisma:client Prisma Client call: +2ms prisma:client prisma.user.upsert({ where: { id: 1 }, create: { id: 1, email: "user0@example.com" }, update: {} }) +1ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 1 }, "create": { "id": 1, "email": "user0@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +3ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 2 }, create: { id: 2, email: "user1@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 2 }, "create": { "id": 2, "email": "user1@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 3 }, create: { id: 3, email: "user2@example.com" }, update: {} }) +1ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 3 }, "create": { "id": 3, "email": "user2@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +1ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 4 }, create: { id: 4, email: "user3@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 4 }, "create": { "id": 4, "email": "user3@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 5 }, create: { id: 5, email: "user4@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 5 }, "create": { "id": 5, "email": "user4@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 6 }, create: { id: 6, email: "user5@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 6 }, "create": { "id": 6, "email": "user5@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 7 }, create: { id: 7, email: "user6@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 7 }, "create": { "id": 7, "email": "user6@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 8 }, create: { id: 8, email: "user7@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 8 }, "create": { "id": 8, "email": "user7@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.upsert({ where: { id: 9 }, create: { id: 9, email: "user8@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 9 }, "create": { "id": 9, "email": "user8@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +0ms prisma:client Prisma Client call: +1ms prisma:client prisma.user.upsert({ where: { id: 10 }, create: { id: 10, email: "user9@example.com" }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "upsertOne", "query": { "arguments": { "where": { "id": 10 }, "create": { "id": 10, "email": "user9@example.com" }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: false +1ms prisma:client:engines:resolveEnginePath enginePath /Users/j42/Repros/issue-prisma-580-pg/node_modules/.prisma/client/libquery_engine-darwin-arm64.dylib.node +0ms prisma:client:libraryEngine library starting +211ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library already starting, this.libraryStarted: false +0ms prisma:client:libraryEngine library started +18ms prisma:client Prisma Client call: +255ms prisma:client prisma.post.upsert({ where: { id: 1 }, create: { id: 1, title: "title-0", authorId: 1 }, update: {} }) +1ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 1 }, "create": { "id": 1, "title": "title-0", "authorId": 1 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +27ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 2 }, create: { id: 2, title: "title-1", authorId: 2 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 2 }, "create": { "id": 2, "title": "title-1", "authorId": 2 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 3 }, create: { id: 3, title: "title-2", authorId: 3 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 3 }, "create": { "id": 3, "title": "title-2", "authorId": 3 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 4 }, create: { id: 4, title: "title-3", authorId: 4 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 4 }, "create": { "id": 4, "title": "title-3", "authorId": 4 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 5 }, create: { id: 5, title: "title-4", authorId: 5 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 5 }, "create": { "id": 5, "title": "title-4", "authorId": 5 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 6 }, create: { id: 6, title: "title-5", authorId: 6 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 6 }, "create": { "id": 6, "title": "title-5", "authorId": 6 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 7 }, create: { id: 7, title: "title-6", authorId: 7 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 7 }, "create": { "id": 7, "title": "title-6", "authorId": 7 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 8 }, create: { id: 8, title: "title-7", authorId: 8 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 8 }, "create": { "id": 8, "title": "title-7", "authorId": 8 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 9 }, create: { id: 9, title: "title-8", authorId: 9 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 9 }, "create": { "id": 9, "title": "title-8", "authorId": 9 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.upsert({ where: { id: 10 }, create: { id: 10, title: "title-9", authorId: 10 }, update: {} }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "upsertOne", "query": { "arguments": { "where": { "id": 10 }, "create": { "id": 10, "title": "title-9", "authorId": 10 }, "update": {} }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine sending request, this.libraryStarted: true +0ms prisma:client Prisma Client call: +7ms prisma:client prisma.post.findUnique({ where: { id: 1, OR: [ { author: { id: 1 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 1, "OR": [ { "author": { "id": 1 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 2, OR: [ { author: { id: 2 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 2, "OR": [ { "author": { "id": 2 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 3, OR: [ { author: { id: 3 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 3, "OR": [ { "author": { "id": 3 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 4, OR: [ { author: { id: 4 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 4, "OR": [ { "author": { "id": 4 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 5, OR: [ { author: { id: 5 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 5, "OR": [ { "author": { "id": 5 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 6, OR: [ { author: { id: 6 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 6, "OR": [ { "author": { "id": 6 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 7, OR: [ { author: { id: 7 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 7, "OR": [ { "author": { "id": 7 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 8, OR: [ { author: { id: 8 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 8, "OR": [ { "author": { "id": 8 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 9, OR: [ { author: { id: 9 } } ] } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 9, "OR": [ { "author": { "id": 9 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.post.findUnique({ where: { id: 10, OR: [ { author: { id: 10 } } ] } }) +1ms prisma:client Generated request: +0ms prisma:client { "modelName": "Post", "action": "findUnique", "query": { "arguments": { "where": { "id": 10, "OR": [ { "author": { "id": 10 } } ] } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine requestBatch +8ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +0ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +5ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +0ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +1ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +0ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +1ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +1ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +0ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +1ms prisma:client:request_handler PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) at Pr (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:36:253) at zt.buildQueryError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:978) at zt.requestBatch (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:117:409) at async /Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:4943 { code: 'P2024', clientVersion: '5.8.0-dev.7', meta: { connection_limit: 5, timeout: 10 } } +0ms PrismaClientKnownRequestError: Invalid `prisma.post.findUnique()` invocation in /Users/j42/Repros/issue-prisma-580-pg/index.ts:31:24

28 // Query which causes the error on Prisma Client 5.8.0
29 const posts = await Promise.all([...Array(10)].map((_, i) => i).map((i) => {
30 const id = i + 1;
→ 31 return prisma.post.findUnique(
Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5)
at si.handleRequestError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:6817)
at si.handleAndLogRequestError (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:6151)
at si.request (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:125:5859)
at async l (/Users/j42/Repros/issue-prisma-580-pg/node_modules/@prisma/client/runtime/library.js:130:10025)
at async Promise.all (index 0)
at async main (/Users/j42/Repros/issue-prisma-580-pg/index.ts:29:17) {
code: 'P2024',
clientVersion: '5.8.0-dev.7',
meta: { modelName: 'Post', connection_limit: 5, timeout: 10 }
}
prisma:client:libraryEngine library stopping +10s
prisma:client:libraryEngine library stopped +0ms

</details>

@janpio janpio added the 5.8.0 label Jan 11, 2024
SevInf added a commit to prisma/prisma-engines that referenced this issue Jan 11, 2024
Problem: we awaited spawned future immediately, which kind of makes
spawn useless, effecctively serializing batch requests instead of
executing them in parallel. Affects only the batches that could not be
compated into a single query.

I struggled to reproduce the error in engine's test suite. I suggest we
test it in client instead.

Fix prisma/prisma#22610
@Jolg42 Jolg42 added this to the 5.9.0 milestone Jan 11, 2024
@Jolg42
Copy link
Contributor

Jolg42 commented Jan 11, 2024

Update: @SevInf is working on a fix, stay tuned 📻

@SevInf
Copy link
Member

SevInf commented Jan 11, 2024

@fujita-h @duongdev @jkepps could you please test it out with 5.9.0-integration-engines-5-9-0-3-fix-5-8-0-timeout-9035a1b3236277185290a05f5f4ca9afd179d699.1 version? This is a dev snapshot that contains the fix, it worked on my reproduction of this issue. We don't recommend using dev snapshots in production, but it is good enough to verify the fix, and if all goes well we'll publish a patch release.

Thank you!

SevInf added a commit to prisma/prisma-engines that referenced this issue Jan 12, 2024
Problem: we awaited spawned future immediately, which kind of makes
spawn useless, effecctively serializing batch requests instead of
executing them in parallel. Affects only the batches that could not be
compated into a single query.

I struggled to reproduce the error in engine's test suite. I suggest we
test it in client instead.

Fix prisma/prisma#22610
@fujita-h
Copy link
Author

@SevInf using the dev snapshot you provided, I confirmed that the problem was resolved in both my product and the reproduction repository.

Thank you!

@SevInf SevInf added the domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. label Jan 15, 2024
SevInf added a commit to prisma/prisma-engines that referenced this issue Jan 15, 2024
* qe: Fix timeout errors

Problem: we awaited spawned future immediately, which kind of makes
spawn useless, effecctively serializing batch requests instead of
executing them in parallel. Affects only the batches that could not be
compated into a single query.

I struggled to reproduce the error in engine's test suite. I suggest we
test it in client instead.

Fix prisma/prisma#22610

* Fix wasm

* Use spawn_local for WASM branch

* Address more review comments
SevInf added a commit to prisma/prisma-engines that referenced this issue Jan 15, 2024
* qe: Fix timeout errors

Problem: we awaited spawned future immediately, which kind of makes
spawn useless, effecctively serializing batch requests instead of
executing them in parallel. Affects only the batches that could not be
compated into a single query.

I struggled to reproduce the error in engine's test suite. I suggest we
test it in client instead.

Fix prisma/prisma#22610

* Fix wasm

* Use spawn_local for WASM branch

* Address more review comments
SevInf added a commit that referenced this issue Jan 15, 2024
Should fail until engine update makes it into a client.
@SevInf
Copy link
Member

SevInf commented Jan 15, 2024

Thanks everyone, the fix is released in 5.8.1

SevInf added a commit that referenced this issue Jan 15, 2024
Should fail until engine update makes it into a client.
SevInf added a commit that referenced this issue Jan 15, 2024
Should fail until engine update makes it into a client.
@liyofx
Copy link

liyofx commented Apr 9, 2024

@SevInf Has this fix not been released yet?
v5.12.1,v5.8.1
The problem still exists.

@SevInf
Copy link
Member

SevInf commented Apr 9, 2024

@liyofx as per my last comment, issue reported here was fixed, fix got confirmed by OP and the fix got released in 5.8.1. Whatever you are experiencing is probably not related to this issue. Please, open a new one and provide a reproduction.

@liyofx
Copy link

liyofx commented Apr 10, 2024

@liyofx as per my last comment, issue reported here was fixed, fix got confirmed by OP and the fix got released in 5.8.1. Whatever you are experiencing is probably not related to this issue. Please, open a new one and provide a reproduction.

A new issue has been created here
#23797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. topic: mysql topic: postgresql topic: Timed out fetching a new connection ... from the connection pool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants