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

Failed to start the query engine: Connection refused #74

Closed
AndryHTC opened this issue Dec 7, 2022 · 39 comments
Closed

Failed to start the query engine: Connection refused #74

AndryHTC opened this issue Dec 7, 2022 · 39 comments

Comments

@AndryHTC
Copy link

AndryHTC commented Dec 7, 2022

PrismaClientInitializationError:
  message: Failed to start the query engine: Connection refused
  errorCode: null
  clientVersion: 2.4.5
#0      BinaryEngine._createProcess (package:orm/src/engine_core/binary/binary_engine_io.dart:441:7)
<asynchronous suspension>
#1      BinaryEngine.start (package:orm/src/engine_core/binary/binary_engine_io.dart:333:17)
<asynchronous suspension>
#2      BinaryEngine.request (package:orm/src/engine_core/binary/binary_engine_io.dart:290:5)
<asynchronous suspension>
#3      ModelDelegate.findMany (package:package_name/prisma_client.dart:55755:42)
<asynchronous suspension>
...

The database is PlanetScale, so I don't have any Docker compose file to set up with SSL or other...
Running the Dart Server locally I have no problems, but in staging/production gives me that error (the connection strings are the same).

@medz Anything to suggest?

Originally posted by @AndryHTC in #55 (comment)

@medz
Copy link
Owner

medz commented Dec 8, 2022

@AndryHTC This needs to be investigated why it is rejected, and my usual practice is to manually start the Prisma query engine in the command line window to locate the problem.

@AndryHTC
Copy link
Author

AndryHTC commented Dec 8, 2022

@yahu1031

@AndryHTC
Copy link
Author

AndryHTC commented Dec 9, 2022

@AndryHTC This needs to be investigated why it is rejected, and my usual practice is to manually start the Prisma query engine in the command line window to locate the problem.

I will not refuse a little bit of a guide on how to do it 😄

@syedzainqadri
Copy link

syedzainqadri commented Dec 9, 2022

Hay Facing the same issue
with mysql in development
PrismaClientInitializationError:
message: Failed to start the query engine: Connection refused
errorCode: null
clientVersion: 2.4.5
Can you guide that how can we manually start the prisma query engine

@medz
Copy link
Owner

medz commented Dec 12, 2022

The Prisma query engine is placed in the .dart_tool/prisma directory by default

@AndryHTC
Copy link
Author

AndryHTC commented Dec 12, 2022

I'm sorry @medz, but you aren't suggesting anything useful... Like @EwigSol sad

Can you guide that how can we manually start the prisma query engine

We understand where is the engine... The question is: how can we try to start it? Is a binary without any extension...

Please, give us support 🙏

@medz
Copy link
Owner

medz commented Dec 12, 2022

@AndryHTC @EwigSol Sorry, I understand. Below I will fully describe the specific debugging methods and steps of "Connection refused" in Prisma ORM in the deployed environment

OpenSSL/LibSSL

In the deployment environment, check whether OpenSSL or LibSSL has been installed, and if not, install it.

unix socket blocking

If your database is running locally, then you need to check whether it is blocked by the local unix socket.

Usually manifested as: Connection refused or Connection timed out.

Remote database connection

If your database is running remotely, then you need to check if it is a database connection problem.

Usually you can try to ping or use telnet to check if you can connect to the database.

Local database

If your database is running locally, then you need to check whether it is a problem with the database connection.

Prisma binary engine default location

The default location of the Prisma binary engine is .dart_tool/prisma/query-engine. On Windows, the default location is .dart_tool\prisma\query-engine.exe.

Start parameters

  • --debug: start debug mode, you can see more debug information
  • --enable-raw-queries: enable raw query mode
  • --enable-open-telemetry: enable OpenTelemetry mode
  • --enable-playground: enable GraphQL Playground
  • --datamodel: Prisma schema.prisma content Base64 encoded string, choose one of --datamodel-path
  • --datamodel-path: Prisma schema.prisma file path, choose one of --datamodel
  • --overwrite-datasources: Overwrite database sources
  • --port: start port

The startup parameters in Prisma ORM for Dart are:

PRISMA_DML={Base64 encoded prisma schema content} query-engine --enable-raw-queries --enable-metrics --enable-open-telemetry --port {free port}

Manually start the binary engine

DATABASE_URL={DB connect url} query-engine --enable-raw-queries --enable-playground --enable-metrics --enable-open-telemetry --port {port} --datamodel-path {path to schema.prisma}

@medz
Copy link
Owner

medz commented Dec 12, 2022

Meanwhile, I'm working on a more stable C api query engine, using Rust. However, my personal time is limited, and I can only maintain the binary query engine version for the time being. I think I need help from the community. I have developed a version, but it has not been applied to Prisma ORM for Dart, because it depends on the Prisma engines warehouse (using git for dependency, non-standard release) which leads to huge maintenance costs. The query engine requirement of C API is submitted to Prisma official. Use FFI for data interaction to achieve a more stable engine and Flutter support.

https://github.com/odroe/prisma-query-c-api

@AndryHTC
Copy link
Author

The default location of the Prisma binary engine is .dart_tool/prisma/query-engine. On Windows, the default location is .dart_tool\prisma\query-engine.exe.

First of all... On Windows, I don't find any query-engine.exe, just query-engine exactly like all the other OSes...

The startup parameters in Prisma ORM for Dart are:

PRISMA_DML={Base64 encoded prisma schema content} query-engine --enable-raw-queries --enable-metrics --enable-open-telemetry --port {free port}

Manually start the binary engine

DATABASE_URL={DB connect url} query-engine --enable-raw-queries --enable-playground --enable-metrics --enable-open-telemetry --port {port} --datamodel-path {path to schema.prisma}

I've tried to manually start the binary engine in local - with Ubuntu, MacOS and Windows with WSL - where Prisma works. I've also tried to manually start the binary engine in the deployed environment (where Prisma do NOT work).

All the commands says that the query-engine command is not found...

Local MacOS (where Prisma Works):

project_server % cd .dart_tool 
.dart_tool % cd prisma
prisma % ls                                                                                                                                                                                                                                                                
query-engine

prisma % DATABASE_URL=[url...] query-engine --enable-raw-queries --enable-playground --enable-metrics --enable-open-telemetry --port [port...] --datamodel-path ../../prisma/schema.prisma
zsh: command not found: query-engine

Local Ubuntu (where Prisma Works):

$ cd project_server/
project_server$ cd .dart_tool/
project_server/.dart_tool$ cd prisma
project_server/.dart_tool/prisma$ ls
query-engine

project_server/.dart_tool/prisma$ DATABASE_URL=[url...] query-engine --enable-raw-queries --enable-playground --enable-metrics --enable-open-telemetry --port [port...] --datamodel-path ../../prisma/schema.prisma
query-engine: command not found

Amazon Linux 2 (where Prisma do NOT work):

[project_server]$ cd prisma

[project_server/prisma]$ ls
development.dart  prisma_version.dart  query-engine  schema.prisma

[project_server/prisma]$ DATABASE_URL=[url...] query-engine --enable-raw-queries --enable-playground --enable-metrics --enable-open-telemetry --port [port...] --datamodel-path schema.prisma
bash: query-engine: command not found
[project_server/prisma]$ query-engine
bash: query-engine: command not found

I've lost an entire day trying to start the query-engine even where it works... I don't understand if I'm doing something wrong or if you missed something in the reply.

By the way thank you for replying @medz

@medz
Copy link
Owner

medz commented Dec 15, 2022

@AndryHTC I know what you missed, the download of the query engine is a progressive download based on the demand of the cli command. So if you want to manually debug the binary engine, please use the precache command to download the binary engine. For details, please see https://prisma.pub/reference/cli#precache

@medz
Copy link
Owner

medz commented Dec 15, 2022

image

Replace executable binary name in command line:
DATABASE_URL=[url...] ./query-engine\
  --enable-raw-queries\
  --enable-playground --enable-metrics \
  --enable-open-telemetry --port [port...] \
  --datamodel-path ../../prisma/schema.prisma

@AndryHTC
Copy link
Author

@medz thank you

Replace executable binary name in command line:

At lest we can go further 😄
./query-engine: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory

@medz
Copy link
Owner

medz commented Dec 16, 2022

error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory

@AndryHTC It means that the running environment lacks OpenSSL/LibSSL. My suggestion is to download the query engine in the running environment (CLI will search for the matching version of the local OpenSSL/LibSSL). If this prompt appears after the successful download, it means that OpenSSL/LibSSL is found locally but not sure Its version was then rolled back to LibSSL 1.0 (which is the minimum requirement for the Prisma binary engine to run)

Repair suggestion:

  1. Run openssl version -v to check whether there is this command or a version higher than 1.0 locally
  2. If step 1 is unsuccessful, run ls -l /lib64 && ls -l /usr/lib64 to see what matches it in the output: libssl.so.(\d+.\d+.\d+)
  3. Try to install OpenSSL
  4. After completing step 3, delete the locally cached query engine binary, and use the dart run orm precache command to re-download the binary engine

@AndryHTC
Copy link
Author

  • Run openssl version -v to check whether there is this command or a version higher than 1.0 locally
[ec2-user@ip-**]$ openssl version -v
OpenSSL 1.0.2k-fips  26 Jan 2017

@AndryHTC
Copy link
Author

@medz I've tried to re-run the dart run orm precache -t query as you shown in other issues, but:

[ec2-user@ip-** serverpod_server]$ dart run orm precache -t query
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.

Is this talking about the project folder? It is a serverpod_server one, so there is no main.dart. The start script is the lib/server.dart

@medz
Copy link
Owner

medz commented Dec 17, 2022

image

@AndryHTC
Copy link
Author

... so? How this could help me in any way? 🤣

I will attach the same if you want

sh-4.2$ sudo su ec2-user
[ec2-user@ip-** bin]$ cd
[ec2-user@ip-** ~]$ cd serverpod
[ec2-user@ip-**1 serverpod]$ cd active
[ec2-user@ip-** active]$ cd serverpod_server
[ec2-user@ip-** serverpod_server]$ ls
analysis_options.yaml  aws  bin  CHANGELOG.md  config  docker-compose.yaml  generated  lib  prisma  pubspec.lock  pubspec.yaml  README.md  setup-tables.cmd  web
[ec2-user@ip-** serverpod_server]$ dart run orm precache -t query
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.
[ec2-user@ip-** serverpod_server]$ cd prisma
[ec2-user@ip-** prisma]$ ls
development.dart  schema.prisma

@AndryHTC
Copy link
Author

@medz cleaning dart cache e applying dart pub get the command starts but freezes the server instance (the console and all the calls to the server too)

[ec2-user@ip-** serverpod_server]$ dart pub get
Resolving dependencies... (2.5s)
  _fe_analyzer_shared 50.0.0 (51.0.0 available)
  analyzer 5.2.0 (5.3.1 available)
  build_runner 2.3.2 (2.3.3 available)
  googleapis 7.0.0 (9.2.0 available)
  intl 0.17.0 (0.18.0 available)
  js 0.6.5 (0.6.6 available)
  matcher 0.12.13 (0.12.14 available)
  path 1.8.2 (1.8.3 available)
  serverpod 0.9.20 (0.9.21 available)
  serverpod_auth_server 0.9.20 (0.9.21 available)
  serverpod_client 0.9.20 (0.9.21 available)
  serverpod_serialization 0.9.20 (0.9.21 available)
  serverpod_service_client 0.9.20 (0.9.21 available)
  serverpod_shared 0.9.20 (0.9.21 available)
Got dependencies!
[ec2-user@ip-** serverpod_server]$ dart run orm precache -t query
Building package executable... (15.4s)

@AndryHTC
Copy link
Author

@medz I apologize for being so insistent, but the project is in production and I need to know if I have to fallback into something else

@medz
Copy link
Owner

medz commented Dec 20, 2022

@AndryHTC I'm sorry for not being able to reply to you these few days, because I was infected with COVID-19 these days and I just got better today. I will carefully analyze the entire issue context and mentioned content later, and then create a new example repository to reproduce this bug together.

@medz
Copy link
Owner

medz commented Dec 20, 2022

@AndryHTC I created a new warehouse to deal with this issue, and I have invited you to enter the warehouse (invitation link: https://github.com/odroe/prisma-dart-issue-74/invitations) to submit what you encountered Is there minimal code to reproduce the problem? Then I'd watch your code looking for problems.

@medz
Copy link
Owner

medz commented Dec 20, 2022

The best way is to write a simple deployment dockerfile, so that it is easier for me to grasp the running target environment information to collect problems.

@AndryHTC
Copy link
Author

AndryHTC commented Dec 20, 2022

@AndryHTC I'm sorry for not being able to reply to you these few days, because I was infected with COVID-19 these days and I just got better today. I will carefully analyze the entire issue context and mentioned content later, and then create a new example repository to reproduce this bug together.

@medz you don't have to justify yourself. This is open source software you are not obligated to reply my questions 😊

So... I extremely appreciate your help, and I hope you feel better now.

Can we communicate just for this issue through an IM service? LinkedIn it's ok to me

@AndryHTC
Copy link
Author

@AndryHTC I created a new warehouse to deal with this issue, and I have invited you to enter the warehouse (invitation link: https://github.com/odroe/prisma-dart-issue-74/invitations) to submit what you encountered Is there minimal code to reproduce the problem? Then I'd watch your code looking for problems.

I'm having some difficulty getting my minimal code published. It seems that I need to package a good chunk of the project to make it work, which can be a bit overwhelming. I'm using the Serverpod framework and have set up the infrastructure with a Terraform script on AWS. The deployment is triggered by a GitHub action that is chained to the Serverpod and AWS infrastructure secrets...

And at the end, I'm running into an issue only with the final output of these actions.

Do you have any suggestions or ideas that might help me out to provide you the minimal code to reproduce the issue?

@medz
Copy link
Owner

medz commented Dec 20, 2022

@AndryHTC I created a new warehouse to deal with this issue, and I have invited you to enter the warehouse (invitation link: https://github.com/odroe/prisma-dart-issue-74/invitations) to submit what you encountered Is there minimal code to reproduce the problem? Then I'd watch your code looking for problems.

I'm having some difficulty getting my minimal code published. It seems that I need to package a good chunk of the project to make it work, which can be a bit overwhelming. I'm using the Serverpod framework and have set up the infrastructure with a Terraform script on AWS. The deployment is triggered by a GitHub action that is chained to the Serverpod and AWS infrastructure secrets...

And at the end, I'm running into an issue only with the final output of these actions.

Do you have any suggestions or ideas that might help me out to provide you the minimal code to reproduce the issue?

My only suggestion is to use Docker to write a deployment architecture similar to your actual environment to implement reproduction. Because any runtime environment architecture can be simulated by writing a dockerfile.

This approach requires you to be familiar with Docker and to be able to write dockerize proficiently and successfully.

@medz
Copy link
Owner

medz commented Dec 21, 2022

prisma/prisma#16871 Perhaps my code downloaded the wrong binary engine on the target platform, I will update the code to find the SSL version and release a new version to verify this conjecture.

@medz
Copy link
Owner

medz commented Dec 21, 2022

@AndryHTC
Copy link
Author

prisma/prisma#16553 (comment)

This could be the key to everything... I'll give it a try! 👍
@medz I appreciate all you efforts

medz added a commit that referenced this issue Dec 22, 2022
@medz
Copy link
Owner

medz commented Dec 22, 2022

@AndryHTC Hey, I released 2.4.7-dev.0 refactored platform detection and published it as a separate package.

Can you try to upgrade to version 2.4.7-dev.0 to test whether it is fixed?

@AndryHTC
Copy link
Author

Can you try to upgrade to version 2.4.7-dev.0 to test whether it is fixed?

No joy...

prisma/prisma#16553 (comment)

This could be the key to everything... I'll give it a try! 👍 @medz I appreciate all you efforts

I cannot upgrade my Amazon-Linux-2's openssl version to v.3.0.7

@medz
Copy link
Owner

medz commented Dec 26, 2022

Can you try to upgrade to version 2.4.7-dev.0 to test whether it is fixed?

No joy...

prisma/prisma#16553 (comment)

This could be the key to everything... I'll give it a try! 👍 @medz I appreciate all you efforts

I cannot upgrade my Amazon-Linux-2's openssl version to v.3.0.7

It's such a pity and I feel bad for it.

I'll keep trying to find what's triggering this issue.

@AndryHTC
Copy link
Author

I was able to get it running in the current instance, even with version 2.4.6. I'm not sure how I managed to do it. I'm worried that if the EC2 instance is terminated and re-instantiated, the problem will occur again.

@syedzainqadri
Copy link

How can i do this on a docker container. Should i just pass all of this in my CMD or As a run command i mean this does not make any clear sence to me

@syedzainqadri
Copy link

I was able to get it running in the current instance, even with version 2.4.6. I'm not sure how I managed to do it. I'm worried that if the EC2 instance is terminated and re-instantiated, the problem will occur again.

can you refrence me through this as i am not able to run the prisma engine manually and it is not working by default. on my docker container.

@medz
Copy link
Owner

medz commented Mar 1, 2023

@AndryHTC @syedzainqadri @aschulz90 @jacobaraujo7 https://github.com/odroe/prisma-dart/blob/main/example/simple/Dockerfile I have solved this problem! This dockerfile is for your reference.

@medz medz closed this as completed Mar 1, 2023
@AndryHTC
Copy link
Author

AndryHTC commented Apr 25, 2023

@AndryHTC @syedzainqadri @aschulz90 @jacobaraujo7 https://github.com/odroe/prisma-dart/blob/main/example/simple/Dockerfile I have solved this problem! This dockerfile is for your reference.

@medz Here we are again 😢. We've managed to not touch the production code in the last 2 months but after an Instance destroy/creation here the problem is back.

The Dockerfile is not available anymore... Can you provide the info? How this applies to orm 3.3.0? What is the right time to generate the engine and the client when deploying?

@medz
Copy link
Owner

medz commented Apr 26, 2023

@medz
Copy link
Owner

medz commented Apr 26, 2023

@AndryHTC https://github.com/odroe/prisma-dart/blob/main/Dockerfile Here is a dockerfile that complements the official Dart landscape. Used to satisfy Prisma binary engine runtime dependencies in scratch.

@AndryHTC
Copy link
Author

@AndryHTC https://github.com/odroe/prisma-dart/blob/main/Dockerfile Here is a dockerfile that complements the official Dart landscape. Used to satisfy Prisma binary engine runtime dependencies in scratch.

Thank you. I would like to know what are the minimum steps needed to get it working and the explanation of each one 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants