Skip to content

Commit

Permalink
reproduce interactive transaction timeout bug
Browse files Browse the repository at this point in the history
  • Loading branch information
awinograd committed Sep 30, 2021
1 parent 092a0c1 commit 7c15281
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .env
@@ -1 +1 @@
DATABASE_URL="postgresql://foo:localpassword@localhost:5432/foo"
DATABASE_URL="postgresql://foo:localpassword@localhost:5435/foo"
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -2,17 +2,17 @@
"name": "script",
"license": "MIT",
"devDependencies": {
"prisma": "2.28.0",
"prisma": "3.1.1",
"ts-node": "10.1.0",
"typescript": "4.3.5",
"@types/node": "15.12.4"
},
"scripts": {
"dev:database": "docker run --env POSTGRES_USER=foo --env POSTGRES_PASSWORD=localpassword --publish 127.0.0.1:5432:5432 postgres:11",
"dev:database": "docker run --env POSTGRES_USER=foo --env POSTGRES_PASSWORD=localpassword --publish 127.0.0.1:5435:5432 postgres:11",
"dev": "ts-node ./script.ts"
},
"dependencies": {
"@prisma/client": "2.28.0"
"@prisma/client": "3.1.1"
},
"engines": {
"node": ">=12.2.0"
Expand Down
5 changes: 5 additions & 0 deletions prisma/migrations/20210930141001_init/migration.sql
@@ -0,0 +1,5 @@
-- DropIndex
DROP INDEX "User.email_index";

-- CreateIndex
CREATE INDEX "User_email_idx" ON "User"("email");
1 change: 1 addition & 0 deletions prisma/schema.prisma
Expand Up @@ -5,6 +5,7 @@ datasource db {

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

model Post {
Expand Down
39 changes: 32 additions & 7 deletions script.ts
@@ -1,16 +1,41 @@
import { PrismaClient } from '@prisma/client'
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient()
const prisma = new PrismaClient();

// A `main` function so that you can use async/await
async function main() {
// ... you will write your Prisma Client queries here
const email = `myemail+${Date.now()}@email.com`;

const user = await prisma.$transaction(
async (pris) => {
const u = await pris.user.create({
data: { email },
});

await new Promise((res) => setTimeout(res, 600));

return u;
},
{ timeout: 500 }
);

console.log("Created user", user);

const persistedUser = await prisma.user.findUnique({
where: { id: user.id },
});

if (!persistedUser) {
throw new Error("user not persisted");
}

console.log("Loaded user from db", persistedUser);
}

main()
.catch(e => {
throw e
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect()
})
await prisma.$disconnect();
});
36 changes: 18 additions & 18 deletions yarn.lock
Expand Up @@ -2,22 +2,22 @@
# yarn lockfile v1


"@prisma/client@2.28.0":
version "2.28.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-2.28.0.tgz#6cd91a3c2757814a9454ea23d7e33cd2ff3952db"
integrity sha512-iwdxpy0Nz8N40MnhdlRvhZOBk8+GawpEsY5FU8Tfw1k9rvIeTAi+wBHrqhY8bXq6pneZkzrdQ1Hj3tqkrbRmoQ==
"@prisma/client@3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.1.1.tgz#f4012631528049c22d12b212846dcf503db33cfe"
integrity sha512-8ud8vVFMIg37yrkZ4wPpjKoMxFbCL0Pesq5eyLnag/s0LTKsVEN7ZBIQq9JzWW+AUqOzGKXr2Jt4Sl8xdGI99w==
dependencies:
"@prisma/engines-version" "2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27"
"@prisma/engines-version" "3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f"

"@prisma/engines-version@2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27":
version "2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27.tgz#6dbccdce64f792dbc21c99daef80ec03020c110d"
integrity sha512-BWTvF1mGxjG8EtG215uhxdeW5Uf5aiH4xhfzcFPFC3Ux5BdEM1uEBrLIixX67mI+ZNhqNZSBPf0DSf2I1IsaZw==
"@prisma/engines-version@3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f":
version "3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f.tgz#f9908eb7808f2a546634398063942eaecb2474ef"
integrity sha512-EuEMKLuwIcBO7uInZQHeG1yaywcfl32Tq8TDf5tgLvblk+ka70sej7S67lh3BV5gXMLTc3GdthSHPfDqZEK5uA==

"@prisma/engines@2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27":
version "2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27.tgz#5a563ead03405fc6ccb33fe48f8b3a8712be391e"
integrity sha512-r3/EnwKjbu2qz13I98hPQQdeFrOEcwdjlrB9CcoSoqRCjSHLnpdVMUvRfYuRKIoEF7p941R7/Fov0/CxOLF/MQ==
"@prisma/engines@3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f":
version "3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f.tgz#7b45708e6a42523dc9bc2214e5c62781f608dc3a"
integrity sha512-6NEp0VlLho3hVtIvj2P4h0e19AYqQSXtFGts8gSIXDnV+l5pRFZaDMfGo2RiLMR0Kfrs8c3ZYxYX0sWmVL0tWw==

"@tsconfig/node10@^1.0.7":
version "1.0.8"
Expand Down Expand Up @@ -69,12 +69,12 @@ make-error@^1.1.1:
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

prisma@2.28.0:
version "2.28.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-2.28.0.tgz#33adb56e336d4c4569ec2f49df9b606771df15d0"
integrity sha512-f83KPLy3xk07KMY4e5otNwP2I+GsdftjOfu3e8snXylnyAC1oEpRZNe7rmONr0vAI+Qgz3LFRArhWUE/dFjKIA==
prisma@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.1.1.tgz#4c13c35dd3a58af9134008c8ed0fdc21a632802c"
integrity sha512-+eZtWIL6hnOKUOvqq9WLBzSw2d/EbTmOx1Td1LI8/0XE40ctXMLG2N1p6NK5/+yivGaoNJ9PDpPsPL9lO4nJrQ==
dependencies:
"@prisma/engines" "2.28.0-17.89facabd0366f63911d089156a7a70125bfbcd27"
"@prisma/engines" "3.1.0-24.c22652b7e418506fab23052d569b85d3aec4883f"

source-map-support@^0.5.17:
version "0.5.19"
Expand Down

0 comments on commit 7c15281

Please sign in to comment.