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

Transaction API error: Transaction not found when calling prisma.$disconnect() #21633

Closed
jakowenko opened this issue Oct 26, 2023 · 3 comments
Closed
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: $disconnect topic: interactiveTransactions topic: $transaction Related to .$transaction(...) Client API

Comments

@jakowenko
Copy link

jakowenko commented Oct 26, 2023

Bug description

I am using Prisma in a production environment with horizontally scaling read replicas on AWS Aurora Serverless v2. I've recently incorporated the extension-read-replicas package to use a reader/writer for better performance. I'm having issues with the extension not using new readers as they scale up with the issue described her: prisma/extension-read-replicas#26

One solution I was trying to incorporate was to call $disconnect() after each API request to close the connection and hopefully establish a new one with one of the scaled up replicas. This seems to work except when calling it after a transaction. I get this following error. I found a similar issue here, but the answer was to simply not call $disconnect() which isn't a solution for me.

Transaction API error: Transaction not found. Transaction ID is invalid, refers to an old closed transaction Prisma doesn't have information about anymore, or was obtained before disconnecting.
PrismaClientKnownRequestError: Transaction API error: Transaction not found. Transaction ID is invalid, refers to an old closed transaction Prisma doesn't have information about anymore, or was obtained before disconnecting.
    at mr.transaction (/api/generated/prisma-client/runtime/library.js:113:1497)
    at async Proxy._transactionWithCallback (/api/generated/prisma-client/runtime/library.js:128:8665)
    at <anonymous> (/api/src/api/user/router.ts:98:3)

How to reproduce

I have a transaction similar to this.

await prisma.$transaction(async (tx) => {
    const user = await tx.user.findUnique({
      where: { id },
      select: {
        id: true,
        name: true,
      },
    });

await prisma.$disconnect();

Expected behavior

The connection is closed.

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["clientExtensions", "fullTextSearch", "fullTextIndex", "filteredRelationCount", "orderByNulls"]
  output          = "../generated/prisma-client"
}

generator zod {
  provider = "prisma-zod-generator"
  output   = "../generated/schemas"
}

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

model User {
  id                        String                     @id @default(cuid())
  name                      String

Environment & setup

  • OS: macOS, Amazon Linux 2
  • Database: MySQL 8
  • Node.js version: v18.16.0

Prisma Version

prisma                  : 5.4.2
@prisma/client          : 5.4.2
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine ac9d7041ed77bcc8a8dbd2ab6616b39013829574 (at node_modules/.pnpm/@prisma+engines@5.4.2/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli ac9d7041ed77bcc8a8dbd2ab6616b39013829574 (at node_modules/.pnpm/@prisma+engines@5.4.2/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.4.1-2.ac9d7041ed77bcc8a8dbd2ab6616b39013829574
Default Engines Hash    : ac9d7041ed77bcc8a8dbd2ab6616b39013829574
Studio                  : 0.494.0
Preview Features        : clientExtensions, filteredRelationCount, fullTextIndex, fullTextSearch, orderByNulls
@jakowenko jakowenko added the kind/bug A reported bug. label Oct 26, 2023
@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. topic: $transaction Related to .$transaction(...) Client API team/client Issue for team Client. topic: interactiveTransactions topic: $disconnect labels Oct 26, 2023
@janpio
Copy link
Member

janpio commented Oct 26, 2023

What do we need to reproduce this? Is it as simple as putting your snippet into a script?

@millsp
Copy link
Member

millsp commented Nov 7, 2023

@jakowenko Did you see the message from @janpio? Without additional information to be able to reproduce, we would later close this issue as part of our issue process.

@SevInf
Copy link
Contributor

SevInf commented Jan 16, 2024

Hey @jakowenko.

With the lack of information and our inability to reproduce this issue, we're now closing it. Feel free to comment if you have any updates about it.

Thank you 🙏

@SevInf SevInf closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: $disconnect topic: interactiveTransactions topic: $transaction Related to .$transaction(...) Client API
Projects
None yet
Development

No branches or pull requests

4 participants