MongoServerSelectionError
a-nomad
PROOP

a month ago

Hi Railway Support,

We're experiencing MongoDB connection failures between services in our staging environment.

Problem:

  • Service apostrophe-cms cannot connect to MongoDB service MongoDB-wgiF

  • Error: MongoServerSelectionError: Server selection timed out after 30000 ms

  • Target: mongodb-wgif.railway.internal:27017

  • App crashes and restarts in a loop

Service Details:

  • MongoDB Service: MongoDB-wgiF - redeployed 2 hours ago

  • App Service: apostrophe-cms - deployed 2 hours ago via Railway CLI

  • Environment: Staging

  • Project: [Your project name]

Important Finding:

MongoDB logs show successful connections and authentication:

  • Connection accepted at 09:22:22 and 09:35:38

  • Successfully authenticated

  • Received first command on ingress connection

This indicates:

  • MongoDB is accessible and accepting connections

  • Private network DNS resolution is working

  • Authentication is successful

However, the app still times out when trying to connect, suggesting:

  1. App may be connecting before MongoDB is ready (timing issue)

  1. Connection string format mismatch

  1. App using a different hostname/endpoint than what's working

Troubleshooting Attempted:

  1. white_check_mark emoji Restarted MongoDB service - no change

  1. white_check_mark emoji Redeployed MongoDB service - no change

  1. white_check_mark emoji Verified services show as "online" in dashboard

  1. white_check_mark emoji Confirmed APOS_MONGODB_URI environment variable is set

  1. white_check_mark emoji MongoDB logs show successful connections from other sources

Questions:

  1. Could there be a startup timing issue where the app connects before MongoDB is ready?

  1. Should we add a connection retry/delay mechanism?

  1. Is the connection string format correct for Railway's private network?

  1. Are there any connection pool or timeout settings we should adjust?

Request:

Please investigate why the app cannot connect despite MongoDB accepting other connections successfully. The private network appears functional, but the app service cannot establish a connection.

Thanks!

$20 Bounty

1 Replies

Railway
BOT

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway about 1 month ago


darseen
HOBBYTop 5% Contributor

a month ago

Try adding ?directConnection=true to the end of your connection string. If it doesn't work, you can check this stack overflow thread for more suggested fixes.


Loading...