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

VS Code debugger freeze from time to time, when Prisma Client is involved #23181

Closed
avan2s opened this issue Feb 18, 2024 · 4 comments · Fixed by #23228
Closed

VS Code debugger freeze from time to time, when Prisma Client is involved #23181

avan2s opened this issue Feb 18, 2024 · 4 comments · Fixed by #23228
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: DEBUG
Milestone

Comments

@avan2s
Copy link

avan2s commented Feb 18, 2024

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:

  1. Make sure docker and node 20.10.0 is installed (can also be other node version)
  2. 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
  3. 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
@avan2s avan2s added the kind/bug A reported bug. label Feb 18, 2024
@miguelff miguelff added topic: vscode extension domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. tech/typescript Issue for tech TypeScript. topic: DEBUG bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. bug/2-confirmed Bug has been reproduced and confirmed. and removed topic: vscode extension bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Feb 19, 2024
@janpio janpio changed the title 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 Feb 19, 2024
@janpio janpio added this to the 5.11.0 milestone Feb 23, 2024
@janpio
Copy link
Contributor

janpio commented 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
Copy link
Author

avan2s commented Apr 13, 2024

Hi @janpio tried it again with the new version. Is fixed now, we can debug again - thanks!

@birgersp
Copy link

For me the freeze always happens if I try to break (stop the debugger) at that execute inside a transaction.

const rows = await myClient.myTable.findMany()
console.log(rows.length) // <-- I can stop the debugger at this line and step, no problem

await myClient.transaction(async (tx) => {
	const rows = await tx.myTable.findMany()
	console.log(rows.length) // <-- If I try to stop the debugger at this line, the debugger will freeze up completely
})

@beazergood
Copy link

For me the freeze always happens if I try to break (stop the debugger) at that execute inside a transaction.

const rows = await myClient.myTable.findMany()
console.log(rows.length) // <-- I can stop the debugger at this line and step, no problem

await myClient.transaction(async (tx) => {
	const rows = await tx.myTable.findMany()
	console.log(rows.length) // <-- If I try to stop the debugger at this line, the debugger will freeze up completely
})

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: DEBUG
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants