Repository navigation
Description
Bug description
Since several month my debugger in vscode hangs up in specific lines of codes in several projects related to prisma. I am not the only one. First i thought it is a vscode issue. So i raised an issue on microsoft vscode repo. It came out, that prisma client is causing this issue by causing a maximum call stack size exceeded error (see here)
The microsoft support team idendified the issue in the following lines in prisma
Prisma defines the const customInspect = Symbol.for('nodejs.util.inspect.custom') and vscode (and i think also other IDEs) use these for watching variables. With that knowledge i also created another repository to reproduce the deep issue. There is also a inital repo, i provided to microsoft, where you can debug (see how to reproduce section). The debugger freeze and you can not go to the next step anymore. Only console.log statements help. Hard bugs are nearly impossible to fix or take to much time.
I would appreciate if the prisma team can fix this issue as soon as possible. Otherwise developers are unable to debug any related prisma code (especially in prisma interactive transactions these occurs more often or if you created a simple extended client) in specific scenarios.
How to reproduce
In general calling Symbol.for('nodejs.util.inspect.custom') function from prisma is causing the issue and leads to infinite call stack.
You have 2 options:
Option 1: Go to the initial microsoft issue. There is a real life project, where you can reproduce the hang up by debugging like in usual node projects: microsoft/vscode#205226 (comment) and follow the reproducing steps.
Option 2: The more deep reproducing issue, which is the inital cause of the problem. It simulates watching variables in vscode debugger:
- Make sure docker and node 20.10.0 is installed (can also be other node version)
- Clone repository and install dependencies
git clone [email protected]:avan2s/prisma-vscode-debugger-hangup.git && cd prisma-vscode-debugger-hangup && npm i && npm run test - never come back again. It runs forever and causes
RangeError: Maximum call stack size exceeded
Expected behavior
The debugger from vscode and other ides is not hanging up. Maybe removing the symbol Symbol.for('nodejs.util.inspect.custom') from the client will already fix the issue. But prisma team have to decide.
Prisma information
any schema will reproduce the issue. I would recommend checking out the tag from how to reproduce. In my case it is:
// 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"
url = env("DATABASE_URL")
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @db.VarChar(255)
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}
model Profile {
id Int @id @default(autoincrement())
bio String?
user User @relation(fields: [userId], references: [id])
userId Int @unique
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
profile Profile?
}vitest test code for reproducting the issue:
import { Prisma, PrismaClient } from '@prisma/client';
import { expect, describe, it } from 'vitest';
describe('reproducting the debugger hangup issue from prisma, whenever your are debugging prisma related stuff - there is a risk, vscode hangs up', () => {
it('should take long time or hang up for prisma client debug variables for prisma client', async () => {
const prisma = new PrismaClient();
await prisma.$connect();
// takes way to long or hangs up
expect(prisma).toBeDefined();
(prisma as any)[Symbol.for('nodejs.util.inspect.custom')]();
})
it('should take long time or hang up for prisma client debug variables in tx client', async () => {
const prisma = new PrismaClient();
expect(prisma).toBeDefined();
await prisma.$connect();
const x = await prisma.$transaction(async (txClient) => {
// takes way to long or hangs up
(txClient as any)[Symbol.for('nodejs.util.inspect.custom')]();
return 0;
});
});
it('should take long time or hang up for prisma client debug variables in extended client', async () => {
const extension = Prisma.defineExtension({
client: {
$log: (s: string) => console.log(s)
}
})
const prisma = new PrismaClient().$extends(extension);
expect(prisma).toBeDefined();
await prisma.$connect();
await prisma.$log("foo");
// takes way to long or hangs up
(prisma as any)[Symbol.for('nodejs.util.inspect.custom')]();
});
it('throws an error while calling inspect custom', async () => {
const extension = Prisma.defineExtension({
client: {
$log: (s: string) => console.log(s)
}
})
const prisma = new PrismaClient().$extends(extension);
expect(prisma).toBeDefined();
await prisma.$connect();
await prisma.$log("foo");
const x = await prisma.$transaction(async(tx) => {
try {
(tx as any)[Symbol.for('nodejs.util.inspect.custom')]();
} catch(ex) {
// here also error occured
expect((ex as any).message).toBe("'ownKeys' on proxy: trap result did not include '$use'");
}
return 0;
});
});
})Environment & setup
- OS: macOS, Ubuntu 22.04
- Database: PostgreSQL (i asume all databases)
- Node.js version: v20.10.0
Prisma Version
>=5.0
Activity
[-]vscode debugger freeze from time to time, when prisma client is involved[/-][+]VS Code debugger freeze from time to time, when Prisma Client is involved[/+]fix(client): Prevent nodejs from hanging on console.log/util.inspect …
fix(client): Prevent nodejs from hanging on console.log/util.inspect …
janpio commentedon Mar 4, 2024
Hey @avan2s, could you please try to temporarily install prisma@dev and @prisma/client@dev in your project and see if this fixes the problem? #23228 should have fixed this and will be included in the next release, but of course a confirmation of it now working as intended would be nice.
avan2s commentedon Apr 13, 2024
Hi @janpio tried it again with the new version. Is fixed now, we can debug again - thanks!
birgersp commentedon Jun 19, 2024
For me the freeze always happens if I try to break (stop the debugger) at that execute inside a transaction.
beazergood commentedon Aug 28, 2024
I'm experiencing the same issue only when inside a transaction. Have you found a fix? I've updated @prisma/client package to 5.19.0 but still have the issue.