Database private url not working.
Previously my project used the database public url and I just tried to switch to the private url and this is the issue I encounter: https://i.mrxbox98.me/file/2024/02/chrome_mqtsKLgRWC.png
100 Replies
Project ID:
b820c80e-50e9-475a-85c6-89832fccdd8c
b820c80e-50e9-475a-85c6-89832fccdd8c
Could you try adding a 3 second sleep in your start command?
reason for this is because private networking takes a bit to initialize, so adding a 3 second sleep will allow it to initialize fully before connecting
but that kinda looks like the build logs? if so, the private network is not yet available to the builder
oh true, didn't notice that
So I should us the database_url for build then the private for runtime?
correct, or depending on what you are doing with the database during build, you can move it to runtime before your app starts (but use a health check so that railway knows when your app is ready to handle traffic)
Ty, also will using my private url reduce the egress charge from my database if the query is from a deployment in the same project?
if you only ever use the private url to connect to the database, there will be zero egress costs for database <--> service data transfer
ty
Im getting this issue even when I have a 10 second sleep in the start of my app
are you using alpine?
Not sure, I dont use a docker container im just using the default nodejs
you dont use a dockerfile?
No i just use the nixpack thing
show me how you have implemented the sleep
I use sveltekit so I put a 10 second sleep in the server.hooks.ts. I tested in a dev env to make sure it actually delays app startup.
did you await the sleep?
yep
can you add the sleep to your start command instead
also, the database is in the same project right?
Yep
would it be something like
sleep 10 && npm start
yeah
ok ill try that
https://i.mrxbox98.me/file/2024/02/chrome_3gvlfUGDZX.png still encountering the issue
ill check in my postgres logs to see if there are any errors there i can match up
Im getting that in my postgres logs a lot
Tagging on this I had a really similar issue yesteday what worked for me was changing
postgres.railway.internal
to just postgres
as the hostname.Ty, ill try to see if that works
Quick question, did you hardcode the variable in? I use prisma so im unable to do a replace
You should have something like this in your prisma schema file, the connection string should come from a env variable it shouldn't be hard coded, from there you should have your reference variable from the database service something like:
REDIS_URL=${{Redis.REDIS_URL}}
And you can modify is as you wish or you could just grab it directly and put it there.
If I do that though the url ends up having postgres.railway.internal in it
Still facing the issue (sorry I’m on phone)
can you connect to the database publicly?
Ill try the public url and see if that fixes it
Havent faced the issue yet with the public url but Ill give it a day to check. I would rather use the private url though to reduce egress costs
Been about 8 hours and havent gotten any issues
@Brody ^ for visibility
Still no issues, hopefully this will get fixed soon so I won't go broke from egress charges
build logs please https://bookmarklets.up.railway.app/log-downloader/
I removed some lint warnings since it showed some irrelevant source code
now deploy logs please
From when I use the private url or the public one?
private
why run install twice?
didnt realize that, ill remove it
can you show me your code of the postgres client?
I use prisma
whats the difference between those two urls?
I use the public url for directUrl because thats what the prisma migrate uses
gotcha, good to know
what is
DATABASE_URL
set to on your service?DATABASE_URL is the private url in this deployment
did you hardcode it?
yes
please use reference variables
But I can undo the hardcoding if needed
I can send a deployment logs of a deployment where it used reference variables
That is where it used reference variables
show me the reference variable you used for database_url please
deploy logs for the database please
have you tried redeploying the database
ill try
Same issue on redeployment, I can send latest logs if you wish
would you be open to adding me to your project?
Sure
Whats your github?
im talking railway project
How do I add?
from the project settings
fair warning i would be able to see your variables
since id need to be an editor to be of any help
No worries, what email should I invite?
invited
one min
so what do we have going on, are these services the same?
1 service is a discord bot that uses hte postgres data but that hasnt ecountered any issues
the other is the web application that is facing problems
both look like they have lots of errors
The discord bot has a lot of errors but none are the postgres connection error
so i can ignore the bot
Yeah
i may have asked already but whats the tech stack of the site? prisma and?
sveltekit and prisma
Maybe the issue occurs after the web server crahes once due to an unrelated reason then on the automatic restart the issues start occuring
I'd recommend moving the sleep into the start script
I had done that before (via the hooks.ts) method but it also didn’t work
https://discord.com/channels/713503345364697088/1136319185882984598 this person seems to have had the same issue
please add it to your start script
start script please, that's the start command
Ok added
Still happening https://i.mrxbox98.me/file/2024/02/chrome_PZiBegAly0.png
stop your app from crashing 🤣
:legostare:
idk why the internal network dns goes down if my deployment crashes then automatically restarts
i don't know either, but..
I'm not joking
ik its a working temporary solution, but i hope railway team fixes the issue soon because i dont want my entire site to go down until i redeploy if something else causes a exit & reboot
I wouldn't go pinning this on railway just yet
it worked well with the public url and i think the only difference in the private one is the dns
heres a log of my database test service crash looping, i have modified the code to exit with an error and have railway restart on crashes, the deployment now sits in a crashed state yet no tests failed
so yes while having to put the 3 second sleep there in the first place is an issue with railway (and will be fixed) with the 3 second sleep there is no issues, the issue would likely lie in your code
Maybe since my application is crashing the db connection is being unexpectedly closed causing something wierd to happen?
because it looks like the deployment is resolving the dns properly
yep so where back to this, railway may be able to fix the need for the sleep, but doesn't help if your app is misbehaving, only you can fix your code
wierd that it only happens on the private url tho. wouldnt the private and public basically act the same since the dns resolved properly
I'm sorry I have no clue what is happening with your code, but I can't reduce this, my code closes connections before exiting with a non zero code
No worries, ill try to debug by changing aroud some prisma settings etc..
I was able to fix the initial crash. Basically I used a library that created a connection on an api call to an external server, but this connection was never closed. At one point the sockets run out so the nodejs runtime crashes on a fetch request. I still can't be 100% sure why the postgres wasn't able to connection because of this, maybe because even after the node proccess restarted the sockets were still used.
awsome!