question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve error message when client fails to connect to a mongodb database

See original GitHub issue

Hi Prisma Team! My Prisma Client just crashed. This is the report:

Versions

Name Version
Node v14.16.1
OS debian-openssl-1.1.x (WSL)
Prisma Client 2.21.2
Query Engine query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d
Database undefined

Query

query {
  findManyusers {
    id
    username
    collapsed
    darktheme
  }
}

Logs

isma:engine stdout  Started http server on http://127.0.0.1:44611  
  prisma:engine Search for Query Engine in /home/jhemphill/data-model/node_modules/.prisma/client  
  plusX Execution permissions of /home/jhemphill/data-model/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x are fine  
  prisma:engine Client Version: 2.21.2  
  prisma:engine Engine Version: query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d  
  prisma:engine Active provider: mongodb  
  prisma:engine stderr  [query-engine/connectors/mongodb-query-connector/src/error.rs:28] &self = DriverError(  +30s
  prisma:engine stderr      Error {  
  prisma:engine stderr          kind: ServerSelectionError {  
  prisma:engine stderr              message: "Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: localhost:27017, Type: Unknown, Error: Connection refused (os error 111) }, ] }",  
  prisma:engine stderr          },  
  prisma:engine stderr          labels: [],  
  prisma:engine stderr      },  
  prisma:engine stderr  )  
  prisma:engine stdout  PANIC in query-engine/connectors/mongodb-query-connector/src/error.rs:115:75
not yet implemented  
  prisma:engine {
  prisma:engine   error: SocketError: other side closed
  prisma:engine       at Socket.onSocketEnd (/home/jhemphill/data-model/node_modules/@prisma/client/runtime/index.js:25205:24)
  prisma:engine       at Socket.emit (events.js:327:22)
  prisma:engine       at Socket.EventEmitter.emit (domain.js:467:12)
  prisma:engine       at endReadableNT (internal/streams/readable.js:1327:12)
  prisma:engine       at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  prisma:engine     code: 'UND_ERR_SOCKET'
  prisma:engine   }
  prisma:engine }  
  prisma:engine { cwd: '/home/jhemphill/ciwi/data-model/prisma' }  
  prisma:engine Search for Query Engine in /home/jhemphill/data-model/node_modules/.prisma/client  
  plusX Execution permissions of /home/jhemphill/data-model/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x are fine  +30s
  prisma:engine {
  prisma:engine   flags: [
  prisma:engine     '--enable-experimental=microsoftSqlServer,mongodb,mongodb',
  prisma:engine     '--enable-raw-queries',
  prisma:engine     '--port',
  prisma:engine     '42905'
  prisma:engine   ]
  prisma:engine }  
  prisma:engine stdout  Started http server on http://127.0.0.1:42905  
  prisma:engine Search for Query Engine in /home/jhemphill/data-model/node_modules/.prisma/client  
  plusX Execution permissions of /home/jhemphill/data-model/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x are fine  
  prisma:engine Client Version: 2.21.2  
  prisma:engine Engine Version: query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d  
  prisma:engine Active provider: mongodb  
  prisma:engine stderr  [query-engine/connectors/mongodb-query-connector/src/error.rs:28] &self = DriverError(  +30s
  prisma:engine stderr      Error {  
  prisma:engine stderr          kind: ServerSelectionError {  
  prisma:engine stderr              message: "Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: localhost:27017, Type: Unknown, Error: Connection refused (os error 111) }, ] }",  
  prisma:engine stderr          },  
  prisma:engine stderr          labels: [],  
  prisma:engine stderr      },  
  prisma:engine stderr  )  
  prisma:engine stdout  PANIC in query-engine/connectors/mongodb-query-connector/src/error.rs:115:75
not yet implemented  
  prisma:engine {
  prisma:engine   error: SocketError: other side closed
  prisma:engine       at Socket.onSocketEnd (/home/jhemphill/data-model/node_modules/@prisma/client/runtime/index.js:25205:24)
  prisma:engine       at Socket.emit (events.js:327:22)
  prisma:engine       at Socket.EventEmitter.emit (domain.js:467:12)
  prisma:engine       at endReadableNT (internal/streams/readable.js:1327:12)
  prisma:engine       at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  prisma:engine     code: 'UND_ERR_SOCKET'
  prisma:engine   }
  prisma:engine }  

Client Snippet

import { PrismaClient } from '.prisma/client/index.js';

const prisma = new PrismaClient();

async function main() {
	const allUsers = await prisma.users.findMany();
	console.log(allUsers);
}

main()
	.catch((e) => {
		throw e;
	})
	.finally(async () => {
		await prisma.$disconnect();
	});

Schema

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

generator client {
    provider        = "prisma-client-js"
    previewFeatures = ["microsoftSqlServer", "mongodb"]
}

model users {
    id        String @id @default(dbgenerated()) @map("_id") @db.ObjectId
    username  String @unique
    collapsed String
    darktheme String
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
pantharshit00commented, May 17, 2021

Its not a panic now in version 2.23.0-dev.37 but it is still ugly. We should improve it: image

$ ts-node main.ts
(node:24044) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.user.findMany()` invocation:


 Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: localhost:27017, Type: Unknown, Error: No
connection could be made because the target machine actively refused it. (os error 10061) }, ] }" } })
   at cb (C:\Users\harshit\code\reproductions\issue-6760\node_modules\@prisma\client\runtime\index.js:35105:17)
   at processTicksAndRejections (internal/process/task_queues.js:95:5)
   at main (C:\Users\harshit\code\reproductions\issue-6760\main.ts:6:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:24044) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing ins
ide of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termin
ate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodej
s.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)(node:24044) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
1reaction
janpiocommented, Apr 26, 2021

Ok thanks. Now we know the circumstances, still a bug as you did not get a good error message but the Engine panicked instead. We can fix that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Connection Issues — MongoDB Atlas
Atlas allows client connections only from IP addresses and CIDR address ranges ... an error stating connection refused because too many open connections...
Read more >
I suddenly became unable to connect ...
I have been using mongoDb for quite a while. And only a few days ago I was able to dump mongodb. I usually...
Read more >
Having trouble connecting to MongoClient before calling ...
The error is suggesting that the program is invoking the mongo.db("main") before the connecting to the server at mongo.connect(...) . This is ...
Read more >
let MongoDB return errors instead of preventing them
For performance purpose, would it be a bad practice to let mongodb handle the errors instead of trying to avoid them in advance?...
Read more >
Improved Error Messages for Schema Validation in ...
Schema validation ease-of-use will be significantly improved by generating descriptive error messages whenever an operation fails validation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found