R
Railwayβ€’15mo ago
Spacemandev

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

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.
24 Replies
Percy
Percyβ€’15mo ago
Project ID: c7f62dd5-665b-4f22-9f49-a2a9e9b19231
Spacemandev
SpacemandevOPβ€’15mo ago
c7f62dd5-665b-4f22-9f49-a2a9e9b19231
Brody
Brodyβ€’15mo ago
can you show me a screenshot of the service variables for the service that can't connect?
Spacemandev
SpacemandevOPβ€’15mo ago
they are the same on both services ( i copy pasted from the one that can connect to the one that can't)
No description
Brody
Brodyβ€’15mo ago
you shouldn't copy paste the database variables, please delete that database variable and setup a variable reference like that popup wants you to
Spacemandev
SpacemandevOPβ€’15mo ago
okay, set up a variable reference, but still same error
Brody
Brodyβ€’15mo ago
can I see another screenshot, just as a sanity check
Spacemandev
SpacemandevOPβ€’15mo ago
'
No description
Brody
Brodyβ€’15mo ago
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
Spacemandev
SpacemandevOPβ€’15mo ago
No description
Spacemandev
SpacemandevOPβ€’15mo ago
the service isn't using a variable reference right now cause for production i'm planning on moving to neon.tech for my postgres deploy, and use railway for just the services
Brody
Brodyβ€’15mo ago
gotcha are you utilizing the private network at all?
Spacemandev
SpacemandevOPβ€’15mo ago
nope
Brody
Brodyβ€’15mo ago
wanna go ahead and disable it?
Spacemandev
SpacemandevOPβ€’15mo ago
disabled redeploying
Brody
Brodyβ€’15mo ago
let the stuff redeploy and get back to me
Spacemandev
SpacemandevOPβ€’15mo ago
ooh looks like disabling private networking fixed it! the service is working! thank you!
Brody
Brodyβ€’15mo ago
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
Spacemandev
SpacemandevOPβ€’15mo ago
is there a reason my other service worked fine? 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
Brody
Brodyβ€’15mo ago
there are many factors, one of the factors I can comment on would be that private networking initialisation times vary slightly
Spacemandev
SpacemandevOPβ€’15mo ago
vs the service that wasn't working, where it's a cron script that calls the db straight away
Brody
Brodyβ€’15mo ago
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
Spacemandev
SpacemandevOPβ€’15mo ago
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 πŸ˜„
Brody
Brodyβ€’15mo ago
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
Want results from more Discord servers?
Add your server