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

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

2 years ago

b1a874f5-6306-4f25-887a-f8f72c50aa76


2 years ago

are you trying to connect to mongo during build?


zoeytabmedia
HOBBYOP

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


2 years ago

can you please use a reference variable -

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

zoeytabmedia
HOBBYOP

2 years ago

I already do


zoeytabmedia
HOBBYOP

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

2 years ago

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


zoeytabmedia
HOBBYOP

2 years ago

This is the result when using the reference


zoeytabmedia
HOBBYOP

2 years ago

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


2 years ago

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


zoeytabmedia
HOBBYOP

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


2 years ago

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


zoeytabmedia
HOBBYOP

2 years ago

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


2 years ago

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


zoeytabmedia
HOBBYOP

2 years ago

👀 I smell a lil oopsie on my side


2 years ago

yeah the private network is ipv6 only


zoeytabmedia
HOBBYOP

2 years ago

Thanks Brody, this helped a lot


2 years ago

up and running?


2 years ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...