Unstable connection to MongoDB via private network
aalfath
PROOP

2 years 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

18 Replies

aalfath
PROOP

2 years ago

a764e147-c28b-4388-85d2-547de92d2fd0


brody
EMPLOYEE

2 years ago

dockerfile or nixpacks based build?


aalfath
PROOP

2 years ago

It's nixpacks-based build.


aalfath
PROOP

2 years ago

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


brody
EMPLOYEE

2 years ago

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


aalfath
PROOP

2 years ago

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


brody
EMPLOYEE

2 years 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 almost 2 years ago


aalfath
PROOP

2 years 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
EMPLOYEE

2 years ago

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


aalfath
PROOP

2 years ago

I see… Gotcha I will try it


aalfath
PROOP

2 years ago

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


aalfath
PROOP

2 years ago

Do I need it to add this option, too?


brody
EMPLOYEE

2 years ago

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


aalfath
PROOP

2 years ago

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


aalfath
PROOP

2 years ago

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


brody
EMPLOYEE

2 years ago

awsome


aalfath
PROOP

2 years ago

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


brody
EMPLOYEE

2 years ago

happy to hear it


Loading...