Unstable connection to MongoDB via private network

aalfath
PRO

a year ago

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',

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!

Solved

0 Replies

aalfath
PRO

a year ago

a764e147-c28b-4388-85d2-547de92d2fd0


a year ago

dockerfile or nixpacks based build?


aalfath
PRO

a year ago

It's nixpacks-based build.


aalfath
PRO

a year ago

node.js based app, but I didn't build the image myself. I let nixpacks build it.


a year ago

do you have a 3 second sleep in your start script?


aalfath
PRO

a year ago

No, I don't have that. Should I add it manually?


a year ago

yes please add a 3 second sleep to the start command so the starting of your app is delayed


Status changed to Solved Railway over 1 year ago


aalfath
PRO

a year 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


a year ago

yes the private network is not available for the first 3 or so seconds


aalfath
PRO

a year ago

I see… Gotcha I will try it


aalfath
PRO

a year ago

Also, I browsed around and it looks like I'd need to add this as well in environment variable:
ENABLEALPINEPRIVATE_NETWORKING=true


aalfath
PRO

a year ago

Do I need it to add this option, too?


a year ago

you said you where using nixpacks right? nixpacks is not based on alpine


aalfath
PRO

a year ago

I see, nevermind then. Yes it's from nixpacks.


aalfath
PRO

a year ago

ok this seems to do the trick. my error is gone now.


a year ago

awsome


aalfath
PRO

a year ago

I even spammed the services and it seems to work fine. access to MongoDB via internal network seems to be stable.


a year ago

happy to hear it


Unstable connection to MongoDB via private network - Railway Help Station