R
Railway•9mo ago
jorgemayto

API Timeout from Mongo

I have deployed a new version to my railway server, I didn't change anything related to my mongodb connection yet now my server is crashing and it is displaying this error, i am using Gunicorn with python flask, it runs perfectly on local with the same command as the one in the server
54 Replies
jorgemayto
jorgemaytoOP•9mo ago
jorgemayto
jorgemaytoOP•9mo ago
project id: 4cc29972-e583-4641-81d0-26868fcc02e7 even deploying an old version that used to work gives the same error
Brody
Brody•9mo ago
is this a mongodb hosted on railway, or elsewhere, like atlas
jorgemayto
jorgemaytoOP•9mo ago
atlas
Brody
Brody•9mo ago
have you whitelisted all ip ranges? 0.0.0.0/0
jorgemayto
jorgemaytoOP•9mo ago
yeah ill delete it and rewhitelist to see if it helps tho
Brody
Brody•9mo ago
please send a screenshot of that setting too
jorgemayto
jorgemaytoOP•9mo ago
No description
Brody
Brody•9mo ago
is that 0.0.0.0/0 network access rule set on the correct database?
jorgemayto
jorgemaytoOP•9mo ago
yeah its the only one i have
Brody
Brody•9mo ago
okay, can you show me the client code that connects to the database
jorgemayto
jorgemaytoOP•9mo ago
from pymongo import MongoClient
import certifi
from models.config import MONGO_DB_URL

class MongoDB:
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)

cls._instance.client = MongoClient(MONGO_DB_URL)
cls._instance.db = cls._instance.client["bookitspot"]
return cls._instance.db

db = MongoDB()
from pymongo import MongoClient
import certifi
from models.config import MONGO_DB_URL

class MongoDB:
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)

cls._instance.client = MongoClient(MONGO_DB_URL)
cls._instance.db = cls._instance.client["bookitspot"]
return cls._instance.db

db = MongoDB()
MONGO_DB_URL = "mongodb+srv://username:password@cluster/?retryWrites=true&w=majority"
MONGO_DB_URL = "mongodb+srv://username:password@cluster/?retryWrites=true&w=majority"
Brody
Brody•9mo ago
and where do you have that service variable set?
jorgemayto
jorgemaytoOP•9mo ago
the connection url? or the actual db variable?
Brody
Brody•9mo ago
both
jorgemayto
jorgemaytoOP•9mo ago
my root folder is called v2 the connection url is inside: v2 -> models -> config.py the db variable is set inside -> v2 -> models -> database -> db_connection.py the code i sent for the connection is the whole db_connection.py file this is how I grab that variable to use: from models.database.db_connection import db
Brody
Brody•9mo ago
so you are hardcoding the url?
jorgemayto
jorgemaytoOP•9mo ago
yeah, how else would I do it?
Brody
Brody•9mo ago
set it as a service variable https://docs.railway.app/guides/variables#service-variables then read the variable from the environment in code
jorgemayto
jorgemaytoOP•9mo ago
ok ill try
Brody
Brody•9mo ago
i saw that lol
jorgemayto
jorgemaytoOP•9mo ago
just realized how lol
Brody
Brody•9mo ago
always a quick google away! 🙂
jorgemayto
jorgemaytoOP•9mo ago
indeed ok just tried and getting the same error
from pymongo import MongoClient
import certifi
# from models.config import MONGO_DB_URL
import os

class MongoDB:
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)

db_url = os.environ['DB_URL']
cls._instance.client = MongoClient(db_url)

cls._instance.db = cls._instance.client["bookitspot"]
return cls._instance.db

db = MongoDB()
from pymongo import MongoClient
import certifi
# from models.config import MONGO_DB_URL
import os

class MongoDB:
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)

db_url = os.environ['DB_URL']
cls._instance.client = MongoClient(db_url)

cls._instance.db = cls._instance.client["bookitspot"]
return cls._instance.db

db = MongoDB()
Brody
Brody•9mo ago
you have set it as a service variable?
jorgemayto
jorgemaytoOP•9mo ago
yeah
jorgemayto
jorgemaytoOP•9mo ago
No description
Brody
Brody•9mo ago
please do not use a shared variable for this
jorgemayto
jorgemaytoOP•9mo ago
ok i think ive set it as a service var now i reset the server and still error
Brody
Brody•9mo ago
show me the service variables please
jorgemayto
jorgemaytoOP•9mo ago
No description
Brody
Brody•9mo ago
and you are sure that is set correctly?
jorgemayto
jorgemaytoOP•9mo ago
i pressed on new variable and pasted my url
Brody
Brody•9mo ago
why not just run mongo on railway?
jorgemayto
jorgemaytoOP•9mo ago
idk this is just how I set it up before I even set up the server but it was working all the time, until today, my server was even running fine in the morning with the same setup
Brody
Brody•9mo ago
my current thought process is that atlas has blocked the shared ip that you are trying to connect from
jorgemayto
jorgemaytoOP•9mo ago
usually i get a different error when it doesnt allow the IP
Brody
Brody•9mo ago
im not talking about the access rules
jorgemayto
jorgemaytoOP•9mo ago
ah
Brody
Brody•9mo ago
would you be interested in running a mongo database on railway?
jorgemayto
jorgemaytoOP•9mo ago
hmm probably not, as i already have this setup
Brody
Brody•9mo ago
unfortunaly it doesn’t seem like its going to work out
jorgemayto
jorgemaytoOP•9mo ago
i feel like there has to be a way to make it work again, since its been working for over a month
Brody
Brody•9mo ago
you could get in contact with atlas
jorgemayto
jorgemaytoOP•9mo ago
ok yh ive opened a ticket with them to see what they say, its so strange tbh as there is nothing online abt the error too hey i did some more testing with different versions of packages and i think it's due to my dnspython package version Locally im using version 2.4.2, but even on local when I update it to latest version it gives me the same error Now, I set the version for dnspython==2.4.2 on my requiremenets.txt file but when I check the build logs on the server it's installing the latest version #10 16.45 Successfully installed Flask-3.0.0 Flask-Cors-4.0.0 Jinja2-3.1.2 MarkupSafe-2.1.3 PyJWT-2.8.0 Werkzeug-3.0.1 anyio-4.3.0 bcrypt-4.0.1 bidict-0.23.1 blinker-1.7.0 certifi-2023.7.22 cffi-1.16.0 charset-normalizer-3.3.2 click-8.1.7 cloudinary-1.38.0 cryptography-41.0.5 dnspython-2.6.1 eventlet-0.34.2 exceptiongroup-1.2.0 flask_socketio-5.3.6 gevent-24.2.1 gevent-websocket-0.10.1 greenlet-3.0.3 gunicorn-21.2.0 h11-0.14.0 h2-4.1.0 hpack-4.0.0 httpcore-1.0.4 httpx-0.26.0 hyperframe-6.0.1 idna-3.4 importlib-metadata-7.0.1 itsdangerous-2.1.2 packaging-23.2 pycparser-2.21 pymongo-4.6.0 python-dateutil-2.8.2 python-engineio-4.9.0 python-socketio-5.11.1 requests-2.31.0 simple-websocket-1.0.0 six-1.16.0 sniffio-1.3.1 typing-extensions-4.10.0 urllib3-2.0.7 wsproto-1.2.0 zipp-3.17.0 zope.event-5.0 zope.interface-6.2 its installing dnspython-2.6.1 which I don't want How can I change the version since I thought it pulled from the requierements file?
Brody
Brody•9mo ago
by specifying the wanted version in your requirements.txt
jorgemayto
jorgemaytoOP•9mo ago
this is what i have there:
dnspython==2.4.2
dnspython==2.4.2
but its not installing that version
Brody
Brody•9mo ago
you have a different version set elsewhere or you haven't pushed those changes
jorgemayto
jorgemaytoOP•9mo ago
thats crazy it works now it was legit just the version of that thank you a lot for your time
Brody
Brody•9mo ago
interesting, well my apologies for sending you in the wrong direction, it was really looking like an IP ban from atlas
jorgemayto
jorgemaytoOP•9mo ago
dont worry, mongo support couldnt even help aswell
Brody
Brody•9mo ago
I don't think there's anyone who could have helped with such an obscure cause of this issue
jorgemayto
jorgemaytoOP•9mo ago
yeah it was weird
Brody
Brody•9mo ago
but happy you found a solution!
Want results from more Discord servers?
Add your server