Skip to content

Spike in Unable to start a transaction in the given time. for new prisma-client #27990

Open

Description

@iamnafets

Bug description

We're experiencing a spike in errors like this after migrating to the new prisma-client and driverAdapters:

Invalid `prisma.pageView.createMany()` invocation: Transaction API error: Unable to start a transaction in the given time.

It doesn't effect 99% of our requests but crashes those that do get this error. We were not experiencing this error with prisma-client-js.

Severity

🚨 Critical: Data loss, app crash, security issue

Reproduction

Do not have a stable reproduction.

Expected vs. Actual Behavior

No errors.

Frequency

Intermittent / Random

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

Worked in 6.9.0, broken in 6.14.0.

Workaround

No workaround ATM.

Prisma Schema & Queries

model PageView {
  id        String   @id @default(cuid())
  userId    String?
  sessionId String?
  pathName  String
  referrer  String
  timestamp DateTime

  @@index([userId])
  @@index([sessionId])
  @@index([timestamp])
  @@index([pathName])
}
                        pageViews.push({
                            userId: typedPayload.user.userID,
                            sessionId: typedPayload.user.customIDs?.stableID,
                            pathName: typedPayload.metadata.pathname,
                            referrer: typedPayload.metadata.referrer,
                            timestamp: DateTime.fromMillis(typedPayload.timestamp).toJSDate(),
                        });
...

                    await prisma().pageView.createMany({
                        data: pageViews
                    });

Prisma Config

No prisma config.

Logs & Debug Info

// Debug logs here

Environment & Setup

  • OS: Debian
  • Database: Postgres / Aurora Serverless RDS
  • Node.js version: 22.18.0

Prisma Version

6.14.0

Activity

  1. added
    kind/bug
    on Aug 28, 2025
  2. changed the title [-]Spike in `Unable to start a transaction in the given time.` for new `sentry-client`[/-] [+]Spike in `Unable to start a transaction in the given time.` for new `prisma-client`[/+] on Aug 29, 2025
  3. jkomyno commented on Aug 29, 2025

    @jkomyno
    Contributor

    Hi @iamnafets, can you please post your generator and datasource blocks from your schema.prisma file, as well as the snippet you're currently using to initialize your PrismaClient instance?

    Also, does the same problem arise when using prisma-client without driverAdapters?

    Thanks.

  4. nickluger commented on Sep 7, 2025

    @nickluger

    Can confirm massive transaction timeout spikes (both, starting transactions and executing within timeout) since using the new adapters without Rust binary. Just reverted to previous setup, as not enough time to evaluate things currently.

    generator client {
    // changed from prisma-client-js
      provider        = "prisma-client"
    // changed from Rust binary
      previewFeatures = ["relationJoins", "queryCompiler", "driverAdapters"]
    // changed from node_modules
      output          = "./src/generated"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }

    Init:

    export function makePrismaClient({
      clientOptions,
      databaseUrl,
    }: MakePrismaClientOptions) {
      const adapter = new PrismaPg({
        connectionString: databaseUrl,
      });
      return new PrismaClient({
        ...clientOptions,
        adapter,
      });
    }
  5. iamnafets commented on Sep 7, 2025

    @iamnafets
    Author

    Hi @iamnafets, can you please post your generator and datasource blocks from your schema.prisma file, as well as the snippet you're currently using to initialize your PrismaClient instance?

    Also, does the same problem arise when using prisma-client without driverAdapters?

    Sure thing!

    generator client {
      provider        = "prisma-client"
      output          = "../client"
      previewFeatures = ["relationJoins", "queryCompiler", "driverAdapters"]
      // previewFeatures = ["relationJoins", "postgresqlExtensions"]
      runtime         = "nodejs"
      moduleFormat    = "esm"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
      // Extension handled in migrations; no automatic creation
    }
    function createPrismaClient(url?: string) {
      const p = new RawPrismaClient({
        // datasources: {
        //   db: {
        //     url: url ?? "", // This will be undefined during builds
        //   },
        // },
        adapter: new PrismaPg({
          connectionString: url ?? env.DATABASE_URL,
          min: 2,
          idleTimeoutMillis: 5 * 60 * 1000, // 5 minutes to reconnect
          connectionTimeoutMillis: 10 * 1000, // 10 seconds to connect
          maxLifetimeSeconds: 15 * 60, // 15 minutes
          max: 10,
        }),
        log:
          // ["error","warn","query"] // For query logging
          (env.NODE_ENV === "development" ? ["error", "warn"] : ["error"]) as Array<Prisma.LogLevel>,
      }).$extends({
        name: "Extensions",
        result: {
          completion: {
            ast: {
              needs: { ast: true },
              compute(completion) {
                return completion.ast as PromptASTNode[];
              }
            },
            inputs: {
              needs: { inputs: true },
              compute(completion) {
                return completion.inputs as PromptRecord;
              }
            }
          },
          mockSatisfactionSurvey: {
            variableQuestions: {
              needs: { variableQuestions: true },
              compute(survey) {
                return survey.variableQuestions as SessionSatisfactionSurveyVariableQuestions;
              }
            }
          },
          // ... More extensions ...
        }
      });
    
      return p;
    }
    
    
    export type PrismaClient = ReturnType<typeof createPrismaClient>;

    The problem indeed happens regardless of whether we're using driver adapters, switched to driver adapters to see if we could fix the issue.

  6. jkomyno commented on Sep 8, 2025

    @jkomyno
    Contributor

    The problem indeed happens regardless of whether we're using driver adapters

    So, to properly understand:

    • You're experiencing transaction errors on Postgres RDS even when using the "old" Rust query engine
    • You're only experiencing this problem with prisma-client, not prisma-client-js
    • You've only noticed this problem in 9.14.0

    This seems quite odd.

    Can you please try again with the following configurations, and report back with the result?

    1. [email protected] + prisma-client-js + previewFeatures = ["relationJoins"]
    // ./schema.prisma
    
    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["relationJoins"]
      output          = "./src/generated/prisma"
    }
    // ./src/db.ts
    import { PrismaClient } from './generated/prisma/client';
    
    export function makePrismaClient({
      clientOptions,
    }: MakePrismaClientOptions) {
      return new PrismaClient({
        ...clientOptions,
      });
    }
    pnpm prisma generate
    1. [email protected] + prisma-client + previewFeatures = ["relationJoins"]
    // ./schema.prisma
    
    generator client {
      provider        = "prisma-client"
      previewFeatures = ["relationJoins"]
      output          = "./src/generated/prisma"
    }
    // ./src/db.ts
    import { PrismaClient } from './generated/prisma/client';
    
    export function makePrismaClient({
      clientOptions,
    }: MakePrismaClientOptions) {
      return new PrismaClient({
        ...clientOptions,
      });
    }

    Can you also try again with Driver Adapters without specifying custom input parameters to PrismaPg, besides the connection string?

    const adapter: new PrismaPg({
      connectionString: url ?? env.DATABASE_URL,
    })

    Thanks!

  7. added
    topic: $transaction
    bug/1-unconfirmed
    on Sep 8, 2025
  8. iamnafets commented on Sep 8, 2025

    @iamnafets
    Author

    I can confirm the issue persists without any custom parameters to the PrismaPg adapter. I ran that before attempting to solve the problem with these parameters.

    Is there a sensible way for me to hook telemetry to these specific errors? I want to make sure I'm giving you something data-driven so I'd love to put a prometheus metric on these transaction-level events so I can track before and after.

  9. Kila14 commented on Sep 17, 2025

    @Kila14

    The same issue
    prisma 6.16.2

  10. 19 remaining items

  11. jacek-prisma commented on Nov 12, 2025

    @jacek-prisma
    Contributor

    Hi @iamnafets @yharaskrik @Kila14 @HubbardJacob @ozgurozalp @TaylorFacen @sosafe-robert-mcauley ,
    We've released a fix that should resolve some cases of this error in version 6.18.0. Can you let us know if you're still seeing this issue on Prisma 6.18.0 or newer?
    Thanks

  12. egoldschmidt commented on Nov 13, 2025

    @egoldschmidt

    FWIW we are also seeing this in 6.18 / Node 24 (using the Rust-free engine + pg adapter)

  13. sosafe-robert-mcauley commented on Nov 14, 2025

    @sosafe-robert-mcauley

    I don't have load testing tools in my staging environment to test a potential fix for this issue, so I am hesitant to deploy a new version that may or may not fix the issue. I do not want to risk pushing to production and having another outage incident. I'll have to wait until others have tested and confirmed that it has been fixed before we try the new engine.

  14. ihadabs commented on Nov 30, 2025

    @ihadabs

    We are also seeing this in 7.0.1 / Node 22 (Rust-free engine + pg adapter)

  15. jsmircic commented on Dec 2, 2025

    @jsmircic

    maybe unrelated as we are using Azure SQL Db, but after migrating to 6.19 and "rust free" we get weird connection errors, after some time looks like connection pooler gets stuck and we see lots of:

    2025-12-02T13:32:25.6619785Z Unhandled promise rejection at: Promise {
    2025-12-02T13:32:25.6621007Z   <rejected> TransactionError: Can't rollback transaction. There is a request in progress.
    
    2025-12-02T13:32:49.7728766Z TimeoutError: operation timed out for an unknown reason
    2025-12-02T13:32:49.7729695Z     at /usr/app/dist/node_modules/tarn/dist/PendingOperation.js:17:27 {
    2025-12-02T13:32:49.7729774Z   clientVersion: '6.19.0'
    2025-12-02T13:32:49.7729851Z }
    

    errors.. Reverting back to rust engine for now.

  16. Sriram-52 commented on Dec 9, 2025

    @Sriram-52

    We attempted to implement the Rust-free upgrade in a staging environment for a client, but it proved to be entirely ineffective. The upgrade introduced numerous issues, including a persistent spike in database connections reaching approximately 170. This spike, coupled with slow read and write operations to the database, rendered the upgrade unusable. Consequently, we have decided to downgrade the system to version 6.5 for the time being.

  17. arthur-ver commented on Dec 21, 2025

    @arthur-ver

    Switching to the new rust-free engine with @prisma/adapter-mssql introduced lots of TransactionError: Can't rollback transaction. There is a request in progress. errors that weren't present with any Prisma version previously. Reverting back to rust engine as well for now.

  18. SylvainMarty commented on Jan 16, 2026

    @SylvainMarty

    I have seen similar issues with Prisma 7 and @prisma/adapter-pg and had to rollback.

    After comparing the code changes in the new update, it looks like Prisma now handles the maxWait option (2 seconds by default) differently when acquiring a new connection and starting a transaction.

    Both implementations rely on setTimeout(), which is inherently non-deterministic and sensitive to Node.js event loop load. However, the behavior changed significantly:

    • The new code makes the timeout and the connection acquisition compete via a Promise.race.
    • The old code (v6.10) simply awaited the connection promise and relied on a best-effort timeout callback running independently.

    Under event loop pressure, the old implementation could allow startTransaction() to resolve after maxWait was exceeded, simply because the timeout callback did not get CPU time before clearTimeout() was called. In practice, this meant timeouts were often missed.

    With the new implementation, the timeout is now part of the control flow and deterministically enforced. This likely explains why maxWait timeouts surface much more frequently under the same load: previously hidden pool starvation or backpressure is now made explicit.

    If this analysis is correct, one possible workaround is to increase the maxWait value. Prisma already supports connection_timeout for Postgres with a default of 5 seconds, which may also help Postgres users.

    This issue also seems related to #20015, which discusses how the default maxWait effectively overrides connection_timeout and pool_timeout settings.

    Could someone confirm whether this interpretation matches the intended behavior change?

  19. wthrajat commented on Jan 31, 2026

    @wthrajat

    Also getting this in [email protected], node 24.13.0 (the current LTS) (Rust-free engine + pg adapter)

  20. SupertigerDev commented on May 6, 2026

    @SupertigerDev

    any updates on this issue?

  21. sosafe-robert-mcauley commented on May 8, 2026

    @sosafe-robert-mcauley

    Chiming in - we have not updated from Prisma 6.19 as we wait for updates on this issue. Other teams in my company updated to Prisma 7, for lower-traffic services, with no issue, but for high-traffic services we are still avoiding the update.

    If it helps any, a few more details on our setup that caused this issue:

    • We are connecting to Amazon RDS Postgres 17.7 servers clusters (no intermediate pooling)
    • Our application maintains two prisma client instances, the same schema but different connection strings: one to our main read+write DB and one to a read-only replica. (e.g. const readWritePrisma = new PrismaClient({ datasources: { db: { url: readWriteUrl } } }); const readOnlyPrisma = new PrismaClient({ datasources: { db: { url: readOnlyUrl } } });)
    • We do specify custom connect parameters on both PrismaClients:
      • connection_limit of "10"
      • pool_timeout of "20000", but now that I cross-check Prisma docs, should this be "20" for "20 seconds"? (or better yet, set to "20s"?)
      • max_connection_lifetime of "300", which seems more lined up with Prisma docs (again though, should we specify explicit "300s"?)
      • ssl_mode of "no-verify" (since RDS uses self-signed certs)
  22. Amit0-dev commented on May 21, 2026

    @Amit0-dev

    Hey, I'm using:

    "@prisma/adapter-pg": "^7.8.0",
    "@prisma/client": "^7.8.0"

    and I'm getting the same issue when hitting an API route that uses $transaction().

    Error:

    PrismaClientKnownRequestError:
    Transaction API error:
    Unable to start a transaction in the given time.

    Normal Prisma queries work fine — the issue only happens with transactions.

    I'm using Next.js App Router with a singleton Prisma client setup already in place.

    Is this issue still active, or is there any recommended workaround/fix currently?

  23. sosafe-robert-mcauley commented on May 22, 2026

    @sosafe-robert-mcauley

    As far as the people who got hit by this the hardest and are holding out by continuing to use Prisma 6 can tell - it's still an issue, and there's no workaround, as raising the transaction maxWait has no effect.

  24. Princedewangan101 commented on May 30, 2026

    @Princedewangan101

    const result = await prisma.$transaction(async (tx) => { // --------- }, { maxWait: 5000, timeout: 10000, })

    1. i m using the prisma-client not the prisma-client-js.
    2. use the above code it working i have face the same Transaction api error this solves it , got the solution from prisma doc.
    3. dont add any kind of async operation other that db , i have put redis set get that also give me that damm errors.
    4. keep the $transaction short.
  25. sosafe-robert-mcauley commented on Aug 31, 2026

    @sosafe-robert-mcauley

    Those suggestions are already taken into account for the configuration I had @cekuu35 - we already had fairly significantly raised timeouts in Prisma as well as per-transaction as I noted in my above post #27990 (comment) . I've now since moved away from Prisma for query execution for my project thanks to prisma-kysely, so unfortunately I won't be able to help now in testing possible solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bugtopic: $transactiontopic: generator-tstopic: interactiveTransactionstopic: queryCompilertopic: transaction

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions