Error connecting to database from deployment process

arnorhs
PRO

a year ago

I'm getting an error connecting to a database instance from a different service. This has worked pretty much flawlessly for two years, but now I'm getting this error when the deployment migration is performed from a Dockerfile:

Error: P1001: Can't reach database server at [monorail.proxy.rlwy.net:10861](monorail.proxy.rlwy.net:10861)

The existing service, still running, can connect fine. And I can connect to the database remotely as well.

project: 58cd7410-04d6-4c6e-a74d-fa7c78455231
service: a6f97426-e4a4-4286-a7cf-c259f98f5ff9

0 Replies

a year ago

to be clear, you are getting this error during build or during runtime?


arnorhs
PRO

a year ago

during the build


arnorhs
PRO

a year ago

i've tried re-deployment a couple of times.. it's possible there's an intermittent connection issue, i do not have adequate monitoring


arnorhs
PRO

a year ago

Should I just try again?


arnorhs
PRO

a year ago

I started another attempt


arnorhs
PRO

a year ago

looked like it was able to connect for the 3rd attempt


a year ago

try running your migrations during runtime with the private network


arnorhs
PRO

a year ago

i'll work on that, thanks


arnorhs
PRO

a year ago

so the deployment i did 10m ago was successful, I had not changed anything

I just changed the database variable to use the internal one, and i'm getting the same error I was getting earlier:
#12 1.987 Error: P1001: Can't reach database server at postgres.railway.internal:5432


arnorhs
PRO

a year ago

well.. same, except the reference being to the internal one


arnorhs
PRO

a year ago

is there some particular internal-networking thing I need to enable?


a year ago

change the runtime to v2 in the service settings


arnorhs
PRO

a year ago

i'm not familiar with this setting, is there anything i should know?



a year ago

yep you beat me to it


arnorhs
PRO

a year ago

aight, deploying


arnorhs
PRO

a year ago

same error


a year ago

is your postgres database in the same project and environment?


arnorhs
PRO

a year ago

yes


a year ago

and are you now making the migration during runtime?


arnorhs
PRO

a year ago

no, that's a bigger change, i need to work on that


a year ago

okay then we can try something else for that


arnorhs
PRO

a year ago

is the internal network not available during deployment?


a year ago

you mean to ask if it is available during build, and the answer to that would be no, but lets try change that


a year ago

add a service variable RAILWAY_BETA_ENABLE_BUILD_V2=1


a year ago

more info:


a year ago

for clarity the v2 runtime and v2 builder are separate systems


arnorhs
PRO

a year ago

sorry, yes, build


arnorhs
PRO

a year ago

it does look like it got past the migration this time, so that appears to have worked


arnorhs
PRO

a year ago

sounds like the BUILD_V2 thing will be a nice change for you guys


arnorhs
PRO

a year ago

and me


a year ago

the v2 builder and v2 runtime aim fix so many things and bring so many improvements


arnorhs
PRO

a year ago

though.. it seems like it's failing the health check.. retrying 7 times now


a year ago

what do your deploy logs look like?


arnorhs
PRO

a year ago

deploy log looks like everything is working


arnorhs
PRO

a year ago

service started successfully


a year ago

what is the reason the health check fails?


arnorhs
PRO

a year ago

Attempt #5 failed with service unavailable. Continuing to retry for 4m44s


arnorhs
PRO

a year ago

Attempt #10 failed with service unavailable. Continuing to retry for 2m28s


arnorhs
PRO

a year ago

etc


a year ago

what kind of app is this?


arnorhs
PRO

a year ago

no other log message, and nothing showing up in the deploy log


arnorhs
PRO

a year ago

it's a node.js app


arnorhs
PRO

a year ago

rest api


a year ago

share your build and deploy logs please -


arnorhs
PRO

a year ago

not really comfortable sharing the log in a public forum


a year ago

is there sensitive information in your logs?


arnorhs
PRO

a year ago

well.. it looks like i'm printing out the database url there.. so yeah


arnorhs
PRO

a year ago

separately, something to fix


a year ago

with the username and password?


arnorhs
PRO

a year ago

yeah, the full thing


a year ago

i mean you can edit the logs before you send them



a year ago

do you have a PORT service variable set?


arnorhs
PRO

a year ago

no


arnorhs
PRO

a year ago

it defaults to 8080


a year ago

can you show me your app.listen?


arnorhs
PRO

a year ago

you mean the typescript code?


a year ago

yes it would be code


arnorhs
PRO

a year ago

why?


a year ago

im just trying to work through some debug steps


arnorhs
PRO

a year ago

which question could be answered by that?


arnorhs
PRO

a year ago

this is probably what you are most likely interested in:

1249553277075460000


a year ago

if you arent interested in debugging this ill have to ask you to revert back to the legacy builder and make your migrations during runtime before starting your app


arnorhs
PRO

a year ago

this is parsing process.env


arnorhs
PRO

a year ago

i'm interested in debugging this, but I'm a bit confused how that could help.. the only thing i can think of is:

  • either you think there's a bug in the code

  • you are trying to figure out whether the app is really listening to port 8080

  • you are wondering if the app is listening to only a particular host (it's listning to 0.0.0.0:8080)

and to those, i think it would be more efficient to ask me


arnorhs
PRO

a year ago

it would perhaps be also easier to test out on the dev environment


arnorhs
PRO

a year ago

since i could just push debug changes etc


a year ago

ive been doing this for a while and screenshots of code is far more helpful than a written response


arnorhs
PRO

a year ago

i'm sorry, i'm probably being rude, i'm sorry - in my defense it is 3 am here and i mostly just want to go to bed 🙂


arnorhs
PRO

a year ago

1249555187639783700


a year ago

thank you


a year ago

now whats up with the build logs containing just the health check, and the deploy logs containing both the build and deploy logs?


arnorhs
PRO

a year ago

yeah, that was weird to me.. because that's not what they look like in the UI


a year ago

thats not an edit you did?


arnorhs
PRO

a year ago

it's just how they came out using the bookmarklet


arnorhs
PRO

a year ago

no


arnorhs
PRO

a year ago

and i also had to click the bookmarklet twice.. first time it only downloaded that deploy log, second time it did this weird combo for the other file


arnorhs
PRO

a year ago

i'm assuming it had something to do with the fact that i had the logs open at the time?


arnorhs
PRO

a year ago

possibly i could try to look at the bookmarklet source and debug it


a year ago

it calls railway's api, it doesnt scrape the web page


arnorhs
PRO

a year ago

weird.. i can try clicking it again


a year ago

but im not sure whats going on with the failed health check, can you try removing the health check for now


arnorhs
PRO

a year ago

well.. now the bookmarklet says:

1249556389919985700


a year ago

do you have a deployment open?


arnorhs
PRO

a year ago

🤦‍♂️


arnorhs
PRO

a year ago

same thing .. buildlogsxxx just has the output of the health check


a year ago

interesting, ill have to look into this

1249556889142825000


arnorhs
PRO

a year ago

yeah, if you open the deployment log.. it will give you the actual build log.. concatenated with the output of what should be the deployment log


arnorhs
PRO

a year ago

i'm a bit worried that it will not work if i remove the health check


a year ago

it might not


arnorhs
PRO

a year ago

i'm fine with the currently running one just staying on for a while


arnorhs
PRO

a year ago

until i can figure out this health check thing


arnorhs
PRO

a year ago

i've got to go to bed - I should just start another thread tomorrow, ok?


a year ago

this thread is good


arnorhs
PRO

a year ago

ok, thanks a lot for your help ❤️


a year ago

no problem!


a year ago

fwiw I fixed the bookmarklet, you just have to delete your old one and drag over the new one -


arnorhs
PRO

a year ago

ah, nice


arnorhs
PRO

a year ago

ok, so i've made the same changes in the dev environment, and it's failing the health check in the same way


arnorhs
PRO

a year ago

but i can push code on to there to debug the issue


arnorhs
PRO

a year ago

i'll start by removing the healthcheck to see if it all still works


arnorhs
PRO

a year ago

--
Is anybody watching this thread?

Anyways, I'm still trying to debug this issue. I haven't made changes related to the active deployment, but it is now all of a sudden not able to connect to the database.

This is the same issue that's been happening on and off lately - and my initial suspicion for what was causing the failed migrations during deployment

Can't reach database server at monorail.proxy.rlwy.net:10861\n\nPlease make sure your database server is running at monorail.proxy.rlwy.net:10861.


arnorhs
PRO

a year ago

This is a way bigger issue than anything related to the deploment process


arnorhs
PRO

a year ago

I opened a new issue for this, since it's not really related to the build process


arnorhs
PRO

a year ago

--
on to the previous issue, it looks like disabling the health check did not adversely affect things - and in the dev environment setting the database env var to the internal one + setting

  • runtime: V2

  • RAILWAYBETAENABLEBUILDV2=1

with the disabled health check it really does seem like everything is working and the service does get deployed successfully

But i'd really like to have the health check there.. in cases where for some reason I make a mistake and the service doesn't actually work


a year ago

it was already 3:30am for me when I sent the message for the bookmarklet and I went to bed shortly after that


a year ago

last night I went around enabling the v2 runtime on some services I had that were still using the legacy runtime, and my umami service started failing the health check with the same reason yours did, did you say your app was a nest app?


a year ago

side note, I very much appreciate all the testing you've done!!


a year ago

went to bed before i did more testing last night, but having umami listen on :: instead of 0.0.0.0 allowed the health check to pass and the service to come online without issue


a year ago

cc @char8 runtime v2 health check oddities


arnorhs
PRO

a year ago

wow, dedication, i like it


arnorhs
PRO

a year ago

did you say your app was a nest app?
not a nest app, but a fastify app - some nest setups use fastify - not sure if that's related, but it would seem strange if what software was running could affect the health check


a year ago

it bugged me that it didnt work


arnorhs
PRO

a year ago

i feel you


arnorhs
PRO

a year ago

ah, listening on the ipv6 address space instead


arnorhs
PRO

a year ago

that would make sense


a year ago

i mean it shouldn't make sense, the health check should work for either ipv4 or ipv6


arnorhs
PRO

a year ago

the service is probably not listening to incoming connections on ipv6, let me try this



arnorhs
PRO

a year ago

i'm using 0.0.0.0 which doesn't listen on ipv6 so that would do it


a year ago

ideally you would be able to listen on either ipv4 or ipv6 and the health check would work regardless


arnorhs
PRO

a year ago

yeah, setting to :: should work, good call


arnorhs
PRO

a year ago

i'm testing that right now


arnorhs
PRO

a year ago

if this turns out to be the solution we are golden


arnorhs
PRO

a year ago

i should have read through this: https://docs.railway.app/reference/private-networking 🙂 could have saved me some hours


a year ago

no no, you should not need to listen on ipv6 for the health check, thats a bug


a year ago

but thats the current work around


arnorhs
PRO

a year ago

it literally says:

You will need to bind to a IPv6 port to receive traffic on the private network.


arnorhs
PRO

a year ago

ahh.. i see what you mean


a year ago

right but the health check is not private networking


arnorhs
PRO

a year ago

riight


arnorhs
PRO

a year ago

so this line that says that private networking is not available during the build phase, that's what will no longer be the case for the new builder?


a year ago

thats correct


a year ago

the v2 builder is now a part of the private network


arnorhs
PRO

a year ago

i remember fighing this a bit when i was setting things up initially.. and distinctly remember giving up on the private network for the db connection, probably because of this..

so i might be able to make my db private-network only


a year ago

thats the goal!


arnorhs
PRO

a year ago

that's super nice


arnorhs
PRO

a year ago

btw i really have been happy with railway in general and it has been really solid for me.. been using it now for two years - i think it's an excellent product and kind of overlooked in the dev community - fly.io etc grabbing all the attention


a year ago

even though i dont work for railway, i appreciate that


arnorhs
PRO

a year ago

you don't? you're just really helpful?


arnorhs
PRO

a year ago

how do you know about the RAILWAY_BETA_ENABLE_BUILD_V2 flag etc?


arnorhs
PRO

a year ago

and the bookmarklet .. that's just your own thing to made to make it easier to help people?


a year ago

well i am a mod so i was told many weeks ago about that, but the info has since been made public

and yep the bookmarklet is my own thing, screenshots of code may be helpfull, but screenshots of build logs are rarely helpful


arnorhs
PRO

a year ago

well, who do you work for then?


a year ago

no one


arnorhs
PRO

a year ago

you're at school?


a year ago

nope


arnorhs
PRO

a year ago

just doing this for the pleasure of helping people?


a year ago

yeah!


arnorhs
PRO

a year ago

🙇‍♂️


arnorhs
PRO

a year ago

well, i bought you some trains - let me know if there's ever anything i can help you with


a year ago

thank you so much!! i appreciate that!!


arnorhs
PRO

a year ago

btw the service was deployed successfully after changing the listening address.. so all problems resolved


a year ago

thats awsome!


a year ago

are you now using the private network to run your migrations during build and for regular communication during runtime?


arnorhs
PRO

a year ago

yes


arnorhs
PRO

a year ago

or i'm deploying that to production atm


arnorhs
PRO

a year ago

works on dev


a year ago

sounds good!


arnorhs
PRO

a year ago

btw the new build thing injects a bunch of extra lines into the logs:

INFO[0007] No files changed in this command, skipping snapshotting.

do you know if there's a way to omit these?


arnorhs
PRO

a year ago

i don't see this when building the docker image locally, so i'm not sure what that is


a year ago

the v2 builder doesnt use buildx it uses something else entirely, and its a little more verbose, theres no way to omit that info


arnorhs
PRO

a year ago

ok, thanks anyways


arnorhs
PRO

a year ago

and thanks a lot for your help, i'm running on private networking both in the build and in the runtime 👍 both on dev & production


arnorhs
PRO

a year ago

how do i mark this thread as resolved?


a year ago

thats great, glad the health check issue was a simple fix


a year ago

thats something a mod can only do, ill go find the best message to mark as the solution


a year ago

to recap -

enable the v2 builder and the v2 runtime, if your health check fails, have your app listen on the :: host


a year ago

well the bot is offline so i will mark that as the answer when the bot come back online


arnorhs
PRO

a year ago

i can also summarize:

I was using the public network to run DB migrations during the build process. I started having connectivity issues when doing that. I made my service use the DB's private networking url and enabled the V2 runtime in settings and set the RAILWAY_BETA_ENABLE_BUILD_V2 variable to 1 - this resolved the issue

(there was a bug in the health check, where it was connecting to the service in the ipv6 range, so i had to also enable that for my app - but that was a separate issue)


arnorhs
PRO

a year ago

yes, or your recap, sorry, i started writing before i saw that


a year ago

yours is better, ill use yours


arnorhs
PRO

a year ago

probably more succinct


Error connecting to database from deployment process - Railway Help Station