I'm experiencing issues with private networking between my API and MongoDB services in Railway.
zoeytabmedia
HOBBYOP

a year ago

Current setup:

  • API service using Dockerfile.staging

  • MongoDB service (fully managed by Railway)

  • Both services are in the same project

  • Public networking works fine with monorail.proxy.rlwy.net

  • Private networking fails with ENOTFOUND when using mongodb-woks.railway.internal

I've tried:

  • Using the RAILWAYPRIVATEDOMAIN

  • Setting up service dependencies

  • Ensuring both services have private networking enabled

  • Various MongoDB URI formats with the internal domain

Error received:
getaddrinfo ENOTFOUND mongodb-woks.railway.internal

Could you help me understand:

  1. What's the correct configuration for private networking between services?

  2. Are there specific requirements or steps I'm missing?

  3. How can I debug private networking connectivity issues?

Solved

19 Replies

zoeytabmedia
HOBBYOP

a year ago

b1a874f5-6306-4f25-887a-f8f72c50aa76


a year ago

are you trying to connect to mongo during build?


zoeytabmedia
HOBBYOP

a year ago

No, we're not trying to connect to MongoDB during build. The MongoDB connection only happens at runtime when the application starts. Our Dockerfile.staging shows a two-stage build process that only installs dependencies and builds TypeScript code, without any database connections during the build phase.

The connection issue occurs after deployment, when the running container tries to connect to MongoDB using the private network domain (mongodb-woks.railway.internal).


a year ago

can you please use a reference variable -

MONGODB_URI=${{MongoDB-WOKs.MONGO_URL}}/tabmedia_staging?authSource=admin

zoeytabmedia
HOBBYOP

a year ago

I already do


zoeytabmedia
HOBBYOP

a year ago

error: [Database] MongoDB connection error | error=getaddrinfo ENOTFOUND mongodb-woks.railway.internal {"timestamp":"2025-01-03T17:26:04.568Z"}

error: [Database] Full error object | error={

  "message": "getaddrinfo ENOTFOUND mongodb-woks.railway.internal",

  "reason": {

    "type": "Unknown",

    "servers": {

      "mongodb-woks.railway.internal:27017": {

        "address": "mongodb-woks.railway.internal:27017",

        "type": "Unknown",

        "hosts": [],

        "passives": [],

        "arbiters": [],

        "tags": {},

        "minWireVersion": 0,

        "maxWireVersion": 0,

        "roundTripTime": -1,

        "minRoundTripTime": 0,

        "lastUpdateTime": 1087871448,

        "lastWriteDate": 0,

        "error": {},

        "topologyVersion": null,

        "setName": null,

        "setVersion": null,

        "electionId": null,

        "logicalSessionTimeoutMinutes": null,

        "maxMessageSizeBytes": null,

        "maxWriteBatchSize": null,

        "maxBsonObjectSize": null,

        "primary": null,

        "me": null,

        "$clusterTime": null

      }

    },

    "stale": false,

    "compatible": true,

    "heartbeatFrequencyMS": 10000,

    "localThresholdMS": 15,

    "setName": null,

    "maxElectionId": null,

    "maxSetVersion": null,

    "commonWireVersion": 0,

    "logicalSessionTimeoutMinutes": null

  }

} {"timestamp":"2025-01-03T17:26:04.578Z"}

error: [Database] Stack trace | stack=MongooseServerSelectionError: getaddrinfo ENOTFOUND mongodb-woks.railway.internal

    at _handleConnectionErrors (/usr/src/app/node_modules/mongoose/lib/connection.js:909:11)

    at NativeConnection.openUri (/usr/src/app/node_modules/mongoose/lib/connection.js:860:11) {"timestamp":"2025-01-03T17:26:04.580Z"}

Stopping Container

a year ago

hmmm, not sure why you say that, your current variable is not the same as what i provided


zoeytabmedia
HOBBYOP

a year ago

This is the result when using the reference


zoeytabmedia
HOBBYOP

a year ago

I'm not using it now, I've switched over to using the public network because I couldn't get it working


a year ago

please use the reference variable i provided and then we can go from there


zoeytabmedia
HOBBYOP

a year ago

You're probably right, have been trying so many things I didn't notice you added the ?authSource_admin param at the end. I'll update my config with the provided reference variable now.


a year ago

not saying its going to magically work, but its best to start out with the correct variable first


zoeytabmedia
HOBBYOP

a year ago

It's deploying, but I do see the error above in my Deploy Logs


a year ago

perhaps you have configured mongoose to do an ipv4 lookup instead of a dual stack lookup?


zoeytabmedia
HOBBYOP

a year ago

👀 I smell a lil oopsie on my side


a year ago

yeah the private network is ipv6 only


zoeytabmedia
HOBBYOP

a year ago

Thanks Brody, this helped a lot


a year ago

up and running?


a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...