question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interactive Transaction concurrent writes cause Prisma to hang

See original GitHub issue

Bug description

Most likely related to https://github.com/prisma/prisma/issues/8707

Here is a minimal repo, using postgres DB and Prisma 3.9.1: https://github.com/danielwong2268/test-prisma

When running several concurrent transactions, under some conditions Prisma hangs. Some variables that were toggled was the number of concurrent transactions, whether locking through SELECT FOR UPDATE was used, and whether a delay was introduced to the transaction. A different combination of these three variables yielded different results.

Further description and observations in the readme.

How to reproduce

Go to minimal repo in Bug description and run through steps. CONCURRENCY, WITH_LOCK, and ADD_DELAY variables can be changed within the script.

My observations are here: https://github.com/danielwong2268/test-prisma#current-behavior

Expected behavior

Running with CONCURRENCY=10 and WITH_LOCK=true and ADD_DELAY=true should work, and the final id should be 1 + 10 = 11.

Prisma information

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres:postgres@localhost:5432/test-db"
}

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User?   @relation(fields: [authorId], references: [id])
  authorId  Int?
}

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

Environment & setup

  • OS: Mac OS 11.5.2
  • Database: Postgres 13.3
  • Node.js version: v14.17.3

Prisma Version

prisma                  : 3.9.1
@prisma/client          : 3.9.1
Current platform        : darwin
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio                  : 0.457.0
Preview Features        : interactiveTransactions

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
garrensmithcommented, Feb 25, 2022

@christie-mathews we are actively working on it. We will let you know once we release an improvement.

2reactions
garrensmithcommented, Mar 29, 2022

We have a fix for this over https://github.com/prisma/prisma/pull/12563 and here https://github.com/prisma/prisma-engines/pull/2811

They will need to be reviewed and tested properly but the test should hopefully be in the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transactions and batch queries (Reference) - Prisma
Interactive transactions : pass a function that can contain user code including Prisma Client queries, non-Prisma code and other control flow to be...
Read more >
Transactions - Prisma
Independent writes. $transaction API; Batch operations. Read, modify, write. Idempotent operations; Optimistic concurrency control; Interactive transactions ...
Read more >
Prisma Client Just Became a Lot More Flexible
This example shows how to use a Prisma Client extension to automatically retry transactions that fail due to a write conflict / deadlock...
Read more >
The Ultimate Guide to Testing with Prisma
Learn about mocking and spying, why they are useful, and how they can be done with Prisma Client.
Read more >
Migration troubleshooting in development - Prisma
Causes of schema drift in a development environment. Schema drift can occur if: The database schema was changed without using migrations - for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found