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

PrismaClient proxy create an infinite loop #21615

Closed
JinYuSha0 opened this issue Oct 25, 2023 · 11 comments
Closed

PrismaClient proxy create an infinite loop #21615

JinYuSha0 opened this issue Oct 25, 2023 · 11 comments
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: logging topic: NestJS topic: prisma-client

Comments

@JinYuSha0
Copy link

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",
@JinYuSha0 JinYuSha0 added the kind/bug A reported bug. label Oct 25, 2023
@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. topic: logging labels Oct 26, 2023
@janpio
Copy link
Member

janpio commented Oct 26, 2023

Are you effectively reporting the same problem as #18292?

@JinYuSha0
Copy link
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

@millsp
Copy link
Member

millsp commented Nov 7, 2023

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 🙏

@SevInf
Copy link
Contributor

SevInf commented Nov 22, 2023

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 🙏

@JinYuSha0
Copy link
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
  }
}

@janpio
Copy link
Member

janpio commented Mar 4, 2024

#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?

@YoannBuzenet
Copy link

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

@SevInf
Copy link
Contributor

SevInf commented Mar 18, 2024

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

@jkomyno
Copy link
Contributor

jkomyno commented Apr 8, 2024

Hey @JinYuSha0, did you manage to try prisma@5.11.0 or prisma@5.12.1? If so, can you please confirm that it fixes this problem?

@JinYuSha0
Copy link
Author

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

@SevInf
Copy link
Contributor

SevInf commented May 3, 2024

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!

@SevInf SevInf closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. topic: logging topic: NestJS topic: prisma-client
Projects
None yet
Development

No branches or pull requests

7 participants