9 months ago
i am running a service that connects to redis and postgres. all three are hosted in the same workspace. i have had issues with internal networking, so we are connecting to redis / postgres via the external domain.
when my service builds, it tries to connect to postgres and returns the error message: "error connecting to server: failed to lookup address information: Name or service not known." it then hangs on connecting to redis until it dies.
we do not have any issues with other services connecting to postgres / redis in this way. explicitly setting the dns in the dockerfile has not given my any results.
p.s. i am unsure why this project is not displaying but the project is named pentacle.
Pinned Solution
9 months ago
I cant speak for redis, but postgres is working in my services...
Can you provide more info on how you are accessing the DB, like the part of the config file that use the url, maybe a bad config that's not working with internal... no idea..., mine looks something like:
spring:
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
As you can notice I'm using spring/boot...
In env i'm using this ones:
DB_HOST: 'my-super-postgresql-db.railway.internal' (internal url)
DB_PORT: '5432 ' (internal port, 5432 by default in postgresql)
DB_NAME: railway (same, default value)
DB_USERNAME: well the username of the DB
DB_PASSWORD: and it's password
And of course both services are running in same project/same environment (it doesn't work if not)
Give it a try and let us know
6 Replies
9 months ago
i suppose this is a good time to start the conversation i've been meaning to have around internal networking, as no matter what i do i can't get that to work either, but lets get this working using the external ipv4 implementation first.
9 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 9 months ago
9 months ago
Hi, just to shed some light on the work with internal networking, since I went through a lot of work at the time, these are the main keys to making it work.
Let's assume we have this URL as internal:
some-service.railway.internal
This is the url given in the settings/Networking/Private Networking tab in config of a service (or db or whatever)
I have to 'parse it' to: http://some-service.railway.internal:port
1 - So basically you need to specify the **http**, not https, just plain old http, since its internal (i assume) it doesn't need to be s'ed.
2 - You need to add the port in witch the service is running, this is usually the 'EXPOSE' in dockerfile or similar config in the framework you are using.
3 - If you are running a service (like a DB), that need a different format, note that the public url have a different port that the internal, like postgres for example, you have the public url: `postgresql://postgres:password@some-public-url.rlwy.net:12345/railway` , the internal url will be something like: postgresql://postgres:password@some-public-url.railway.internal:5432/railway Note the change in `some-public-url.rlwy.net` to `some-public-url.railway.internal`, and port from `12345` to `5432`
I don't know if this is some kind of magic, but it do make it work for me... feel free to test it and let me know
9 months ago
I have tested this also with the public URLs and still getting the same errors.
9 months ago
had this same problem before with services trying to connect using external URLs inside the same Railway project.
sometimes DNS fails or it just hangs for a long time.
what worked for me:
- use the internal hostname Railway gives you instead of the public domain.
usually it's something like redis.project-name.internal
- make sure you're also using the internal port (5432 for postgres, 6379 for redis).
you can find the internal hostname and port in the service settings under the "Domains" section.
once I switched to internal hostname + port, everything worked instantly and it was way faster too.
9 months ago
i will give it a try again, but none of our services have ever worked with the internal urls of redis / postgres. i would prefer that as we get to avoid egress costs (i think these would get charged using external) but they never have.
@brody is there anyway we can get actual support here? this project spends ~$350/mo with you guys and we have more to develop. i'm getting to the point where reviewing feasibility of GCP over railway actually seems like a good use of my time.
9 months ago
I cant speak for redis, but postgres is working in my services...
Can you provide more info on how you are accessing the DB, like the part of the config file that use the url, maybe a bad config that's not working with internal... no idea..., mine looks something like:
spring:
datasource:
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
As you can notice I'm using spring/boot...
In env i'm using this ones:
DB_HOST: 'my-super-postgresql-db.railway.internal' (internal url)
DB_PORT: '5432 ' (internal port, 5432 by default in postgresql)
DB_NAME: railway (same, default value)
DB_USERNAME: well the username of the DB
DB_PASSWORD: and it's password
And of course both services are running in same project/same environment (it doesn't work if not)
Give it a try and let us know
Status changed to Solved chandrika • 7 months ago