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:
App may be connecting before MongoDB is ready (timing issue)
Connection string format mismatch
App using a different hostname/endpoint than what's working
Troubleshooting Attempted:
Restarted MongoDB service - no change
Redeployed MongoDB service - no change
Verified services show as "online" in dashboard
Confirmed APOS_MONGODB_URI environment variable is set
MongoDB logs show successful connections from other sources
Questions:
Could there be a startup timing issue where the app connects before MongoDB is ready?
Should we add a connection retry/delay mechanism?
Is the connection string format correct for Railway's private network?
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!
1 Replies
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
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.