R
Railwayβ€’9mo ago
Celengan Babi

Unstable connection to MongoDB via private network

Hi everyone, Just today my app receives some errors in MongoDB connection, below is the log files (I've attached the screenshot, too):
MongoServerSelectionError: getaddrinfo ENOTFOUND mongodb.railway.internal
at Timeout._onTimeout (/app/node_modules/agenda/node_modules/mongodb/lib/sdam/topology.js:292:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'mongodb.railway.internal:27017' => ServerDescription {
address: 'mongodb.railway.internal:27017',
MongoServerSelectionError: getaddrinfo ENOTFOUND mongodb.railway.internal
at Timeout._onTimeout (/app/node_modules/agenda/node_modules/mongodb/lib/sdam/topology.js:292:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'mongodb.railway.internal:27017' => ServerDescription {
address: 'mongodb.railway.internal:27017',
It seems that the URL that should have been set for private networking @ mongodb.railway.internal could not be recognized by my container running in the same project. This problem seems to happen intermittently though. Because my services are live already, I had to switch the MongoDB URL to the public one instead (which would cost me egress network costs). Please let me know if this is a known issue, or if there is anything else that I should do from my side. As a dev, aside from reasons based on the costs, I would also prefer the usage of private network to access the DB. In summary: the private URL access for MongoDB seems to be unstable currently, sometimes the request went thru, sometimes it would just result in a timeout. Thanks a lot!
No description
Solution:
yes please add a 3 second sleep to the start command so the starting of your app is delayed
Jump to solution
20 Replies
Percy
Percyβ€’9mo ago
Project ID: a764e147-c28b-4388-85d2-547de92d2fd0
Celengan Babi
Celengan BabiOPβ€’9mo ago
a764e147-c28b-4388-85d2-547de92d2fd0
Brody
Brodyβ€’9mo ago
dockerfile or nixpacks based build?
Celengan Babi
Celengan BabiOPβ€’9mo ago
It's nixpacks-based build. node.js based app, but I didn't build the image myself. I let nixpacks build it.
Brody
Brodyβ€’9mo ago
do you have a 3 second sleep in your start script?
Celengan Babi
Celengan BabiOPβ€’9mo ago
No, I don't have that. Should I add it manually?
Solution
Brody
Brodyβ€’9mo ago
yes please add a 3 second sleep to the start command so the starting of your app is delayed
Celengan Babi
Celengan BabiOPβ€’9mo ago
ah ok I will add it just a question though: is the 3s sleep relevant to the problem? in my screenshot above, the problem seems to only occur pretty much recently. the deployed image was running properly for days and it never had problem accessing the MongoDB via internal network
Brody
Brodyβ€’9mo ago
yes the private network is not available for the first 3 or so seconds
Celengan Babi
Celengan BabiOPβ€’9mo ago
I see... Gotcha I will try it Also, I browsed around and it looks like I'd need to add this as well in environment variable: ENABLE_ALPINE_PRIVATE_NETWORKING=true Do I need it to add this option, too?
Brody
Brodyβ€’9mo ago
you said you where using nixpacks right? nixpacks is not based on alpine
Celengan Babi
Celengan BabiOPβ€’9mo ago
I see, nevermind then. Yes it's from nixpacks. ok this seems to do the trick. my error is gone now.
Brody
Brodyβ€’9mo ago
awsome
Celengan Babi
Celengan BabiOPβ€’9mo ago
I even spammed the services and it seems to work fine. access to MongoDB via internal network seems to be stable.
Brody
Brodyβ€’9mo ago
happy to hear it
Jijon
Jijonβ€’9mo ago
Hey, it seems i have the same issue, the first 3 seconds of deploy process don't have access to exposed private network ? I have another question, is the private network exposed on all projets of the organization, or is it only accessible through the project?
Brody
Brodyβ€’9mo ago
everyone has the same issue, there is about a 3 second delay for every service deployed to railway before the private network is fully available. the private networks are scoped to a single environment, meaning each environment within a project is its own private network, and services can only talk to other services in the same environment within the same project.
Jijon
Jijonβ€’9mo ago
ok nice, thanks for the explanations πŸ˜„
Brody
Brodyβ€’9mo ago
furthermore, this will be fixed in due time, when fixed there will be zero delay to the availability of the private network when deployments start
Celengan Babi
Celengan BabiOPβ€’9mo ago
Thanks for being helpful as always @Brody!
Want results from more Discord servers?
Add your server