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

Prisma Client hangs and eventually panics when there is no MongoDB server to connect to #6431

Closed
matthewmueller opened this issue Apr 6, 2021 · 3 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb
Milestone

Comments

@matthewmueller
Copy link
Contributor

matthewmueller commented Apr 6, 2021

(MongoDB is not publicly available yet. This issue is for the development build.)

Problem

A mongodb connection string that doesn't have a mongodb server listening hangs and eventually panics after 1 minute.

I first noticed this when I accidentally shutdown my mongodb server and ran my script. The script seemed frozen, but it said it was connected. Then I realized that I had no server listening.

Steps to Reproduce

Given the following Prisma Schema

datasource db {
  provider = "mongodb"
  url      = "mongodb://localhost:27017/mydb"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id    String @id @default(dbgenerated("")) @map("_id")
  email String @unique
}

And the following script

import { PrismaClient } from './@prisma/client'

const client = new PrismaClient()

async function main() {
  console.time('connect')
  await client.$connect()
  console.timeEnd('connect')
  console.time('create')
  const user = await client.user.create({
    data: {
      email: 'max@gmail.com',
    },
  })
  console.log(user)
  console.timeEnd('create')
}

main()
  .catch(console.error)
  .finally(() => client.$disconnect())

Make sure your MongoDB server isn't running

Now if you run that script, you get the following:

$ DEBUG=prisma:client ts-node main.ts
  prisma:client clientVersion: local +0ms
connect: 248.623ms
  prisma:client Prisma Client call: +284ms
  prisma:client prisma.user.create({
  prisma:client   data: {
  prisma:client     email: 'max@gmail.com'
  prisma:client   }
  prisma:client }) +1ms
  prisma:client Generated request: +0ms
  prisma:client mutation {
  prisma:client   createOneUser(data: {
  prisma:client     email: "max@gmail.com"
  prisma:client   }) {
  prisma:client     id
  prisma:client     email
  prisma:client   }
  prisma:client }
  prisma:client  +0ms
  prisma:client Error: PANIC in query-engine/connectors/mongodb-query-connector/src/error.rs:115:75
  prisma:client not yet implemented
  prisma:client 
  prisma:client This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.
  prisma:client 
  prisma:client https://github.com/prisma/prisma/issues/new?body=Hi+Prisma+Team%21+My+Prisma+Client+just+crashed.+This+is+the+report%3A%0A%23%23+Versions%0A%0A%7C+Name++++++++++++%7C+Version++++++++++++%7C%0A%7C-----------------%7C--------------------%7C%0A%7C+Node++++++++++++%7C+v14.16.0+++++++++++%7C+%0A%7C+OS++++++++++++++%7C+darwin+++++++++++++%7C%0A%7C+Prisma+Client+++%7C+local++++++++++++++%7C%0A%7C+Query+Engine++++%7C+query-engine+60ba6551f29b17d7d6ce479e5733c70d9c00860e%7C%0A%7C+Database++++++++%7C+undefined%7C%0A%0A%0A%0A%23%23+Query%0A%60%60%60%0Amutation+%7B%0A++createOneUser%28data%3A+%7B%0A++++email%3A+%22X%22%0A++%7D%29+%7B%0A++++id%0A++++email%0A++%7D%0A%7D%0A%60%60%60%0A%0A%23%23+Logs%0A%60%60%60%0Aprisma%2Fprisma%2Fsrc%2Fpackages%2Fengine-core%2Fsrc%2Fbyline.ts%3A116%3A17%29++%7B%22timestamp%22%3A%22Apr+06+15%3A44%3A45.769%22%2C%22level%22%3A%22ERROR%22%2C%22fields%22%3A%7B%22message%22%3A%22PANIC%22%2C%22reason%22%3A%22not+yet+implemented%22%2C%22file%22%3A%22query-engine%2Fconnectors%2Fmongodb-query-connector%2Fsrc%2Ferror.rs%22%2C%22line%22%3A115%2C%22column%22%3A75%7D%2C%22target%22%3A%22query_engine%22%2C%22span%22%3A%7B%22name%22%3A%22execute_single_operation%22%7D%2C%22spans%22%3A%5B%7B%22name%22%3A%22execute_single_operation%22%7D%5D%7D++%0A++prisma%3Aengine+%7B%0A++prisma%3Aengine+++error%3A+SocketError%3A+other+side+closed%0A++prisma%3Aengine+++++++at+Socket.onSocketEnd+%28%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fnode_modules%2F.pnpm%2Fundici%403.3.3%2Fnode_modules%2Fundici%2Flib%2Fcore%2Fclient.js%3A773%3A22%29%0A++prisma%3Aengine+++++++at+Socket.emit+%28events.js%3A327%3A22%29%0A++prisma%3Aengine+++++++at+Socket.EventEmitter.emit+%28domain.js%3A467%3A12%29%0A++prisma%3Aengine+++++++at+endReadableNT+%28internal%2Fstreams%2Freadable.js%3A1327%3A12%29%0A++prisma%3Aengine+++++++at+processTicksAndRejections+%28internal%2Fprocess%2Ftask_queues.js%3A80%3A21%29+%7B%0A++prisma%3Aengine+++++code%3A+%27UND_ERR_SOCKET%27%0A++prisma%3Aengine+++%7D%0A++prisma%3Aengine+%7D++%0A++prisma%3Aengine+%7B%0A++prisma%3Aengine+++cwd%3A+%27%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fpackages%2Fclient%2Ffixtures%2Fmongo%2Fprisma%27%0A++prisma%3Aengine+%7D++%0A++plusX+Execution+permissions+of+%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fnode_modules%2F.pnpm%2F%40prisma%2Fengines%402.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e%2Fnode_modules%2F%40prisma%2Fengines%2Fquery-engine-darwin+are+fine++%2B30s%0A++prisma%3Aengine+%7B%0A++prisma%3Aengine+++flags%3A+%5B%0A++prisma%3Aengine+++++%27--enable-experimental%3DmongoDb%27%2C%0A++prisma%3Aengine+++++%27--enable-raw-queries%27%2C%0A++prisma%3Aengine+++++%27--port%27%2C%0A++prisma%3Aengine+++++%2759489%27%0A++prisma%3Aengine+++%5D%0A++prisma%3Aengine+%7D++%0A++prisma%3Aengine+stdout++Started+http+server+on+http%3A%2F%2F127.0.0.1%3A59489++%0A++plusX+Execution+permissions+of+%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fnode_modules%2F.pnpm%2F%40prisma%2Fengines%402.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e%2Fnode_modules%2F%40prisma%2Fengines%2Fquery-engine-darwin+are+fine++%0A++prisma%3Aengine+Client+Version%3A+local++%0A++prisma%3Aengine+Engine+Version%3A+query-engine+60ba6551f29b17d7d6ce479e5733c70d9c00860e++%0A++prisma%3Aengine+Active+provider%3A+mongodb++%0A++prisma%3Aengine+stderr++%5Bquery-engine%2Fconnectors%2Fmongodb-query-connector%2Fsrc%2Ferror.rs%3A28%5D+%26self+%3D+DriverError%28++%2B30s%0A++prisma%3Aengine+stderr++++++Error+%7B++%0A++prisma%3Aengine+stderr++++++++++kind%3A+ServerSelectionError+%7B++%0A++prisma%3Aengine+stderr++++++++++++++message%3A+%22Server+selection+timeout%3A+No+available+servers.+Topology%3A+%7B+Type%3A+Unknown%2C+Servers%3A+%5B+%7B+Address%3A+localhost%3A27019%2C+Type%3A+Unknown%2C+Error%3A+Connection+refused+%28os+error+61%29+%7D%2C+%5D+%7D%22%2C++%0A++prisma%3Aengine+stderr++++++++++%7D%2C++%0A++prisma%3Aengine+stderr++++++++++labels%3A+%5B%5D%2C++%0A++prisma%3Aengine+stderr++++++%7D%2C++%0A++prisma%3Aengine+stderr++%29++%0A++prisma%3Aengine+stdout++PANIC+in+query-engine%2Fconnectors%2Fmongodb-query-connector%2Fsrc%2Ferror.rs%3A115%3A75%0Anot+yet+implemented++%0A++prisma%3Aengine+TypeError%3A+this.currentRequestPromise.cancel+is+not+a+function%0A++prisma%3Aengine+++++at+NodeEngine.handlePanic+%28%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fpackages%2Fengine-core%2Fsrc%2FNodeEngine.ts%3A333%3A34%29%0A++prisma%3Aengine+++++at+NodeEngine.setError+%28%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fpackages%2Fengine-core%2Fsrc%2FNodeEngine.ts%3A260%3A14%29%0A++prisma%3Aengine+++++at+LineStream.%3Canonymous%3E+%28%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fpackages%2Fengine-core%2Fsrc%2FNodeEngine.ts%3A667%3A22%29%0A++prisma%3Aengine+++++at+LineStream.emit+%28events.js%3A315%3A20%29%0A++prisma%3Aengine+++++at+LineStream.EventEmitter.emit+%28domain.js%3A467%3A12%29%0A++prisma%3Aengine+++++at+addChunk+%28internal%2Fstreams%2Freadable.js%3A309%3A12%29%0A++prisma%3Aengine+++++at+readableAddChunk+%28internal%2Fstreams%2Freadable.js%3A284%3A9%29%0A++prisma%3Aengine+++++at+LineStream.Readable.push+%28internal%2Fstreams%2Freadable.js%3A223%3A10%29%0A++prisma%3Aengine+++++at+LineStream.Transform.push+%28internal%2Fstreams%2Ftransform.js%3A166%3A32%29%0A++prisma%3Aengine+++++at+LineStream._pushBuffer+%28%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fpackages%2Fengine-core%2Fsrc%2Fbyline.ts%3A116%3A17%29++%7B%22timestamp%22%3A%22Apr+06+15%3A45%3A16.023%22%2C%22level%22%3A%22ERROR%22%2C%22fields%22%3A%7B%22message%22%3A%22PANIC%22%2C%22reason%22%3A%22not+yet+implemented%22%2C%22file%22%3A%22query-engine%2Fconnectors%2Fmongodb-query-connector%2Fsrc%2Ferror.rs%22%2C%22line%22%3A115%2C%22column%22%3A75%7D%2C%22target%22%3A%22query_engine%22%2C%22span%22%3A%7B%22name%22%3A%22execute_single_operation%22%7D%2C%22spans%22%3A%5B%7B%22name%22%3A%22execute_single_operation%22%7D%5D%7D++%0A++prisma%3Aengine+%7B%0A++prisma%3Aengine+++error%3A+SocketError%3A+other+side+closed%0A++prisma%3Aengine+++++++at+Socket.onSocketEnd+%28%2FUsers%2Fm%2Fdev%2Fsrc%2Fgithub.com%2Fprisma%2Fprisma%2Fsrc%2Fnode_modules%2F.pnpm%2Fundici%403.3.3%2Fnode_modules%2Fundici%2Flib%2Fcore%2Fclient.js%3A773%3A22%29%0A++prisma%3Aengine+++++++at+Socket.emit+%28events.js%3A327%3A22%29%0A++prisma%3Aengine+++++++at+Socket.EventEmitter.emit+%28domain.js%3A467%3A12%29%0A++prisma%3Aengine+++++++at+endReadableNT+%28internal%2Fstreams%2Freadable.js%3A1327%3A12%29%0A++prisma%3Aengine+++++++at+processTicksAndRejections+%28internal%2Fprocess%2Ftask_queues.js%3A80%3A21%29+%7B%0A++prisma%3Aengine+++++code%3A+%27UND_ERR_SOCKET%27%0A++prisma%3Aengine+++%7D%0A++prisma%3Aengine+%7D++%0A%60%60%60%0A%0A%23%23+Client+Snippet%0A%60%60%60ts%0A%2F%2F+PLEASE+FILL+YOUR+CODE+SNIPPET+HERE%0A%60%60%60%0A%0A%23%23+Schema%0A%60%60%60prisma%0A%2F%2F+PLEASE+ADD+YOUR+SCHEMA+HERE+IF+POSSIBLE%0A%60%60%60%0A&title=PANIC+in+query-engine%2Fconnectors%2Fmongodb-query-connector%2Fsrc%2Ferror.rs%3A115%3A75%0Anot+yet+implemented&template=bug_report.md
  prisma:client 
  prisma:client If you want the Prisma team to look into it, please open the link above 🙏
  prisma:client To increase the chance of success, please post your schema and a snippet of
  prisma:client how you used Prisma Client in the issue. 
  prisma:client 
  prisma:client     at NodeEngine.throwAsyncErrorIfExists (/Users/m/dev/src/github.com/prisma/prisma/src/packages/engine-core/src/NodeEngine.ts:1085:19)
  prisma:client     at NodeEngine.handleRequestError (/Users/m/dev/src/github.com/prisma/prisma/src/packages/engine-core/src/NodeEngine.ts:1121:10)
  prisma:client     at processTicksAndRejections (internal/process/task_queues.js:93:5)
  prisma:client     at NodeEngine.request (/Users/m/dev/src/github.com/prisma/prisma/src/packages/engine-core/src/NodeEngine.ts:988:7)
  prisma:client     at cb (/Users/m/dev/src/github.com/prisma/prisma/src/packages/client/src/runtime/getPrismaClient.ts:1542:26)
  prisma:client     at main (/Users/m/dev/src/github.com/prisma/prisma/src/packages/client/fixtures/mongo/main.ts:10:16) +1m
PrismaClientUnknownRequestError: 
Invalid `prisma.user.create()` invocation:


  PANIC in query-engine/connectors/mongodb-query-connector/src/error.rs:115:75
not yet implemented

Suggested solution

Two confusing things:

  • It says it's connected. I guess it's connected to the query engine, not to the database. I find this quite confusing, but I think this is also the case for Postgres.
  • It hangs. In this case, it should likely fail fast because there's no port open on the other side.

After 1 minute (see the +1m in debug logs) it crashes with:

PANIC in query-engine/connectors/mongodb-query-connector/src/error.rs:115:75
not yet implemented

This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.
@matthewmueller matthewmueller added kind/improvement An improvement to existing feature and code. topic: mongodb labels Apr 6, 2021
@pantharshit00 pantharshit00 added the team/client Issue for team Client. label Apr 6, 2021
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. and removed kind/improvement An improvement to existing feature and code. labels Apr 6, 2021
@janpio

This comment has been minimized.

@janpio

This comment has been minimized.

@matthewmueller matthewmueller added this to the 2.22.0 milestone Apr 14, 2021
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Apr 19, 2021
@matthewmueller matthewmueller modified the milestones: 2.22.0, 2.23.0 May 5, 2021
@dpetrick
Copy link
Contributor

Please use appropriate connection string arguments. For initial Mongo server selection ("first query") use serverSelectionTimeoutMS=..., for general connection timeouts use connectTimeoutMS=.... Docs are here: https://docs.mongodb.com/manual/reference/connection-string/

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. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb
Projects
None yet
Development

No branches or pull requests

4 participants