Skip to content

PrismaClient proxy create an infinite loop #21615

Closed

Description

@JinYuSha0

Bug description

I use Prisma with nestjs, when my service access the PrismaClient instance enter an infinite loop. causing the service to hang.

I found through the debugger that the infinite loop occurred in @prisma/client/runtime/libary

2023-10-25.20.28.15.mov

I'm sure I didn't use it improperly, Don't know what causes this problem

How to reproduce

@Injectable()
export class RegisterBackend {
  constructor(private readonly prisma: PrismaService) {}

  @Loader()
  async loader(@RemixArgs() _remixArgs: LoaderFunctionArgs) {
    console.log(this) // just access
    return {};
  }

  @Action()
  async post(@Body() body: RegisterDto) {
    return {};
  }
}

Expected behavior

No response

Prisma information

// 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"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model User {
  id          String      @id @default(auto()) @map("_id") @db.ObjectId
  email       String      @unique
  nickname    String
  gender      String
  birthday    DateTime
  password    String
  validated   Boolean
}

Environment & setup

  • OS: macOS
  • Database: MongoDB
  • bun version: 1.0.4

Prisma Version

"@prisma/client": "^5.5.0",
"prisma": "^5.5.0",

Activity

  1. added
    kind/bug
    on Oct 25, 2023
  2. added
    bug/0-unknown
    on Oct 26, 2023
  3. janpio commented on Oct 26, 2023

    @janpio
    Contributor

    Are you effectively reporting the same problem as #18292?

  4. JinYuSha0 commented on Oct 27, 2023

    @JinYuSha0
    Author

    Are you effectively reporting the same problem as #18292?

    I guess so, not sure if this is a problem with nestjs compatibility, I tried to locate the problem, it seems that the _engine attribute is always undefined, Node addons seem to be unable to load, when I switch to singleton pattern everything is fine.

    import { PrismaClient } from '@prisma/client'
    
    const prisma = new PrismaClient()
    
    prisma.$connect().then(() => {
    	console.log('prisma connected')
    })
    
    export default prisma
  5. millsp commented on Nov 7, 2023

    @millsp
    Contributor

    Hey @JinYuSha0, could you please provide us with a reproduction? Without it we will not be able to make progress and will end up closing the issue via our internal process. Thanks 🙏

  6. SevInf commented on Nov 22, 2023

    @SevInf
    Contributor

    Hey @JinYuSha0 ,

    Did you get a chance to have a look at @millsp's previous comment? It'd be helpful for us to move your issue forward.

    Without further information, we'll have to close this issue. Thank you 🙏

  7. JinYuSha0 commented on Nov 22, 2023

    @JinYuSha0
    Author

    @millsp @SevInf
    I'd like to help you, But I can't provide a code repository. If you want to reproduce the issue, try wrapping prisma in a Nest provider, inject it into any service, and access it.

    This problem is still there, I can provide code snippets

    // PrismaProvider.ts
    import { Provider } from '@nestjs/common';
    import { ConfigService } from '@nestjs/config';
    import { PrismaClient } from '@prisma/client';
    
    export const PRISMA = Symbol('PrismaSymbol');
    
    export const PrismaProvider: Provider = {
      provide: PRISMA,
      useFactory: (configService: ConfigService) => {
        return new PrismaClient();
      },
      inject: [ConfigService],
    };
    // CommonModule.ts
    import { PrismaProvider } from '@/common/prisma.provider';
    
    @Global()
    @Module({
      imports: [CacheModule],
      providers: [
        PrismaProvider,
      ],
      exports: [
        PrismaProvider,
      ],
    })
    export class CommonModule {}
    // SomeService.ts
    @Injectable()
    export class SomeService {
     constructor(
        @Inject(PRISMA) private readonly prisma: typeof Prisma,
      ) {}
    
      public async someMethod() {
        this.prisma;  // just access
      }
    }
  8. janpio commented on Mar 4, 2024

    @janpio
    Contributor

    #23228 could 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. Could you please try to temporarily install prisma@dev and @prisma/client@dev in your project and see if this fixes the problem?

  9. YoannBuzenet commented on Mar 7, 2024

    @YoannBuzenet

    I did
    npm install prisma@dev @prisma/client@dev
    and I'm happy to say it works. Thank you !

  10. SevInf commented on Mar 18, 2024

    @SevInf
    Contributor

    @JinYuSha0 could you confirm that the issue is fixed in 5.11 as well?
    Thank you.

  11. jkomyno commented on Apr 8, 2024

    @jkomyno
    Contributor

    Hey @JinYuSha0, did you manage to try [email protected] or [email protected]? If so, can you please confirm that it fixes this problem?

  12. JinYuSha0 commented on Apr 12, 2024

    @JinYuSha0
    Author

    @jkomyno @SevInf Sorry I haven't followed that project for a while, I'll take a look at it over the weekend

  13. SevInf commented on May 3, 2024

    @SevInf
    Contributor

    I am going to close the issue for now. If it still happens for you for prisma 5.11 or creater, feel free to open a new one.
    Thank you!

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/0-unknownkind/bugtopic: NestJStopic: loggingtopic: prisma-client

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions