6 days ago
I am experiencing a persistent network issue with my project and need your assistance. My Node.js/Express backend service is unable to connect to its MySQL database service, and I have exhausted all user-side troubleshooting steps.
The Core Problem:
When my environment variables (like MYSQLHOST
) are correctly linked from the database service, my application fails to connect with an Error: connect ETIMEDOUT
. This indicates a network block, as the connection attempt times out.
To confirm the variables were being loaded, I temporarily removed them from the service. As expected, the error changed to Error: connect ECONNREFUSED ::1:3306
, proving my application was correctly defaulting to localhost
. This test confirms the issue is not with my code but with the network path when the correct host variable is present.
Troubleshooting Steps Already Taken:
I have thoroughly debugged this and can confirm the following:
Correct Configuration: My app and database are in the same project. My start command is
node server.js
, and mypackage.json
is configured correctly.Environment Variables: I have confirmed the variable names are correct. The issue persists whether I use the shared
MYSQLHOST
variable directly or alias it.No Race Condition: I have implemented a connection retry-with-backoff mechanism. The connection fails every time, proving it is not a startup race condition.
Health Checks Passing: I have configured my server to start before initiating the database connection, so my
/api/health
endpoint responds correctly and the service deploys successfully.Service Restarts: I have tried restarting the database service and redeploying my backend multiple times.
Variable Re-linking: I have completely unlinked/deleted all database variables from my backend service, redeployed to clear the configuration, and then re-linked them.
The ETIMEDOUT
error consistently returns, pointing to a platform-level networking issue between my service containers. Could you please investigate the networking for this project?
Thank you for your help.
7 Replies
railway[bot]
6 days ago
Our team is working on getting back to you as soon as possible. In the meantime, we've found the following might help you get unlocked faster:
If you find the answer from one of these, please let us know by solving the thread! Otherwise, we’ll be in touch.
4 days ago
can you confirm that your backend uses Railway’s internal database hostname (not localhost). Confirm the right port (3306) is used and allowed.
Also, test connectivity from inside your backend container to the database. If it still times out, check Railway’s network settings for your project.
4 days ago
Without any sensitive details can you share your environment variable set up? I see you say you have them set up correctly but I am not able to deduce how they are set up
4 days ago
The services within the same project will be able to connect using Railway private network https://docs.railway.com/guides/private-networking#communicating-over-the-private-network
4 days ago
I have found this on another bounty that was responded to by @uzux who is a moderator https://station.railway.com/questions/internal-service-not-connecting-78a08b8e#h3vx
He says:
Hey, private networking is IPv6 only, did you make sure that your new service is also listening on IPv6? https://docs.railway.com/guides/private-networking
3 days ago
Hi Guys thank you for the help I'm not sure what exactly fixed it, but it's working now. I made this change to address the IPv6 suggestion.
// Only add family: 0 if we're using Railway's MySQL host
if (process.env.MYSQLHOST) {
poolConfig.family = 0; // Enable IPv6 support for Railway
}
And I also changed my docker file, one of those changes fixed the issue. Thank you!
johnanderson5
Hi Guys thank you for the help I'm not sure what exactly fixed it, but it's working now. I made this change to address the IPv6 suggestion.// Only add family: 0 if we're using Railway's MySQL host if (process.env.MYSQLHOST) { poolConfig.family = 0; // Enable IPv6 support for Railway }And I also changed my docker file, one of those changes fixed the issue. Thank you!
3 days ago
Thanks for the update, it is great that IPv6 or the dockerfile change fixed the issue. If you don't mind me asking what was the docker file change? It will also help others