#One service is unable to connect to Postgres container, while the other connects fine

37 messages · Page 1 of 1 (latest)

hidden river
#

Hi, I have two typescript services and a postgres service in a project. One of the typescript services is able to connect to the postgres service totally fine while the second one can't.

sweet questBOT
#

Project ID: c7f62dd5-665b-4f22-9f49-a2a9e9b19231

civic kestrelBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

hidden river
#

c7f62dd5-665b-4f22-9f49-a2a9e9b19231

cyan needle
#

can you show me a screenshot of the service variables for the service that can't connect?

hidden river
#

they are the same on both services ( i copy pasted from the one that can connect to the one that can't)

cyan needle
#

you shouldn't copy paste the database variables, please delete that database variable and setup a variable reference like that popup wants you to

hidden river
#

okay, set up a variable reference, but still same error

cyan needle
#

can I see another screenshot, just as a sanity check

hidden river
cyan needle
#

perfect

#

side note, your other service should be using a variable reference if it's not already, don't worry about it stopping working, we will get to the bottom of this

#

so now please show me the error you get

hidden river
cyan needle
#

gotcha

#

are you utilizing the private network at all?

hidden river
#

nope

cyan needle
#

wanna go ahead and disable it?

hidden river
#

disabled

#

redeploying

cyan needle
#

let the stuff redeploy and get back to me

hidden river
#

ooh looks like disabling private networking fixed it! the service is working!

hidden river
civic kestrelBOT
cyan needle
#

okay so why it works, private networking takes about 2 seconds to fully initialise and this can effect calls to things that are not on the private network, if you did happen to be using private networking then you would have needed to increase the timeout to the connection to postgres, but I don't know how that's handled in prisma? maybe a query parameter on the database url variable

hidden river
#

cause that also uses prisma

#

maybe just cause it has an express server and that took the required amount of time before prisma kicked in?

#

oh i guess prisma would only kick in on the working service when i got an inbound request

#

which would be long enough time for private networking to have initialize

cyan needle
#

there are many factors, one of the factors I can comment on would be that private networking initialisation times vary slightly

hidden river
#

vs the service that wasn't working, where it's a cron script that calls the db straight away

cyan needle
#

ah yes if the connection to the database isn't done at app start then initialisation times for the private network wouldn't come into play

hidden river
#

so i could've solved with even just a regular promise timeout in the service that wasn't working before the prisma network initialized. cool, good to know! thank you 😄

cyan needle
#

awaiting a promise timeout, slapping a sleep 2 && onto the start command, increasing connection timeout, use pg_isready
many solutions, all which I wish we didn't have to do

#

this could even effect a connection attempt to neon if the connection is done at app start