Prisma won't connect to Postgres database on Digital Ocean Kubernetes - node.js

I'm trying to run an application in a kubernetes pod that connects to a managed database using Digital Ocean's services. I'm sure the connection string is correct. Running the pod locally on my desktop connects to the database just fine, but when I try to connect from my cloud managed kubernetes instance I get the error ECONNREFUESED
Has anyone ever run into something like this before? (I'm using Prisma and Node.js)
(Both the kubernetes cluster and the postgres database are on Digital Ocean)
Here are the pod logs (I turned on all the prisma logging I could)
prisma:info Starting a postgresql pool with 9 connections.
prisma:info Started http server on http://127.0.0.1:42535
PrismaClientKnownRequestError3 [PrismaClientKnownRequestError]:
Invalid `prisma.user.findUnique()` invocation:
connect ECONNREFUSED ::1:42535
at cb (/app/node_modules/#prisma/client/runtime/index.js:36494:17)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async login (/app/src/gql/Users/resolvers.ts:267:16) {
code: 'ECONNREFUSED',
clientVersion: '2.30.3',
meta: undefined
So, that's what happens when I try to run the "login" mutation, just for an example. Prisma tries to find the user but - it can't connect - and this is the resulting error message.
Again, it's absolutely fine when I run locally in a kubernets pod on my local machine (using docker desktop). I'm sure the user/pass/port is fine because I connect fine with pgAdmin. I'm sure the connection string is correct because it works fine in my local cluster. I'm looking for something - anything - to give a clue why I can't connect from Digital Ocean! I have also tried other database providers with the same result. Error message is always the same, only thing that changes is teh port on the prisma http server. (this is desperation haha). Does anyone have any insight to what could be going on?? What could be different that allows me to connect from docker desktop's kubernetes but prevents it on Digital Ocean's cluster?

Found the "solution". Upgraded to prisma v3.
If you can't do that, there's more info here: https://github.com/prisma/prisma/issues/9899

Related

Cannot connect to SQL Server database on Nodejs EC2 server

I have an EC2 instance running a node server. The pages and routes render fine on the frontend, but when I do anything that requires a call to the api it says failed to connect to XX.XX.X.XXX:1433 (which is my SQL Server database). When I run the app locally (not inside the EC2 instance) it works just fine and connects to the DB. Btw, my local computer is NOT where the SQL Server database is being hosted.
What could the issue be on the instance?
EDIT: TCP is enabled and the Browser part is running in the SQL manager.
EDIT2:This is the error I get every time my EC2 app makes an api call to te database:
ConnectionError: Failed to connect to XX.XX.X.XXX:1433 in 15000ms
But when I do the dame thing on the app from its development computer on localhost it works just fine.
Ok, so, it looks like this is a network connectivity problem. Can you ping the DB server?
ping xx.xx.xx.xx
Second, can you telnet to the port?
telnet xx.xx.xx.xx 1433
My guess is that both of these will fail. So, the question is, why?
Some things to consider:
Is the database server on the public internet? (I hope not, for security reasons.)
Is your client computer on the public internet?
What is the network access path to get from your client machine to the DB server? VPN tunnel? SSLVPN connection? Something else?
I don't have a specific solution for you, but hopefully I gave you some ideas as to where to look. The problem is (almost certainly) not a database problem, but a network connectivity issue.

Use redis as a container in Azure Web App Service

I've been trying for a week now to deploy a Redis Container as a Azure Web App Service, but I can't manage to connect to it, after a few tries some of the logs I got are listed bellow:
The handshake failed due to an unexpected packet format redis
Protocol error, got "H" as reply type byte. Please report this.
Redis error Error: getaddrinfo ENOTFOUND https://*************.azurewebsites.net
Some of the things I tried:
Different doors (80, 6379, random ones I saw in logs)
Different TLS versions
Force https connection
Does anyone of you know if it's possible to do it? I know there's Azure Redis but it's too pricey for a test.
Thanks alot
just figured out.
You actually have to deploy your container image using container instances, pointing the port 6379/TCP.
I did it and it worked fine.

Docker compose/nodejs: Restart required to connect after ECONNREFUSED

I have a docker-compose file. There is a mysql service and a nodejs service (Nestjs using TypeORM). Sometimes when I bring the stack up, the nestjs service tries to connect to the mysql service before it is ready, and gives me a ECONNREFUSED. I've set it up to retry connecting more or less indefinitely, but once mysql is up, it continues to give me the ECONNREFUSED error.
While it is retrying, and once mysql is up, I can connect to the mysql service using nc mysql 3306, confirming it indeed can. But for some reason I continue to get the ECONNREFUSED error. Once I restart the nodejs service it connects properly. The closest I've come to figuring out the problem is perhaps it has something to do with a Connection Pool that is created in the typeorm package. Any idea how I can deal with this?`

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

Connecting to Redis databases via Node in Heroku

About Heroku: App is Nodejs, Express, WebSockets ...
I'm testing an app out on a small free Heroku instance.
I have my own Redis database instances through OpenRedis and RedisToGo.
Those have not been provisioned through Heroku addons but directly from the providers.
I connect to them fine when running locally. What special do I need to do to connect to them through Heroku?
I was kind of hoping to avoid special Heroku-specific environment variables, but am happy to use them if necessary.
But I definitely need to avoid the necessity of provisioning the Redis addons through Heroku.
Again, I have already my database instances provisioned directly with the relevant providers.
Everything works fine locally under NODE_ENV=production npm start, which indicates to my app that it should connect to the remote Redis instances (RedisToGo and/or OpenRedis) instead of the local Redis server.
I'm using Redis for at least three things:
Session store :: Connect-Redis :: This works fine locally (app server running locally but connecting to remote Redis instance) and also seems to work on Heroku-- I've checked by flushing the database and then pushing a slightly new version to Heroku and the session variable key is refreshed.
Database :: Node-Redis :: This works fine locally also (also app server running locally but connecting to remote Redis instance for database), but does not seem to be working on Heroku.
WebSockets Transport Pub/Sub :: I haven't tested this thoroughly. I'm guessing it's working but it's not important for this question.
What is most interesting to me,
is that the Heroku instance is able to connect to the Redis instance via the Connect-Redis client, but is not able to connect to the same Redis instance via the database client. Whereas my locally running version is able to connect to the same (remote) instance via both of these clients. (I have verified these findings through terminal clients, using flushall command and waiting for keys to be refreshed.)
Any insight would be greatly appreciated.
I'll post my edits and updates via comments below because they're timestamped.
It turns out we can't connect to a database (not sure why because I don't know the internals of Heroku's config over AWS) the 'normal' way through Heroku; we need to set the environment variable with the heroku config:set command. OpenRedis provides a terminal ready string, can probably put something similar together for self-provisioned RedisToGo instances, though I haven't done it yet.

Resources