Skip to content

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

Closed

Description

@avan2s

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

Activity

  1. added
    kind/bug
    on Feb 18, 2024
  2. added
    tech/typescript
    bug/1-unconfirmed
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Feb 19, 2024
  3. 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[/+] on Feb 19, 2024
  4. added 2 commits that reference this issue on Feb 21, 2024
    906d6cf
    6c4ea75
  5. added this to the 5.11.0 milestone on Feb 23, 2024
  6. janpio commented on Mar 4, 2024

    @janpio
    Contributor

    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.

  7. avan2s commented on Apr 13, 2024

    @avan2s
    Author

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

  8. birgersp commented on Jun 19, 2024

    @birgersp

    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
    })
    
  9. beazergood commented on Aug 28, 2024

    @beazergood

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtech/typescripttopic: DEBUG

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions