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
project id: 4cc29972-e583-4641-81d0-26868fcc02e7
even deploying an old version that used to work gives the same error
is this a mongodb hosted on railway, or elsewhere, like atlas
atlas
have you whitelisted all ip ranges?
0.0.0.0/0
yeah
ill delete it and rewhitelist to see if it helps tho
please send a screenshot of that setting too
is that
0.0.0.0/0
network access rule set on the correct database?yeah its the only one i have
okay, can you show me the client code that connects to the database
and where do you have that service variable set?
the connection url?
or the actual db variable?
both
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
so you are hardcoding the url?
yeah, how else would I do it?
set it as a service variable https://docs.railway.app/guides/variables#service-variables
then read the variable from the environment in code
ok ill try
i saw that lol
just realized how lol
always a quick google away! 🙂
indeed
ok just tried and getting the same error
you have set it as a service variable?
yeah
please do not use a shared variable for this
ok i think ive set it as a service var now
i reset the server and still error
show me the service variables please
and you are sure that is set correctly?
i pressed on new variable and pasted my url
why not just run mongo on railway?
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
my current thought process is that atlas has blocked the shared ip that you are trying to connect from
usually i get a different error when it doesnt allow the IP
im not talking about the access rules
ah
would you be interested in running a mongo database on railway?
hmm probably not, as i already have this setup
unfortunaly it doesn’t seem like its going to work out
i feel like there has to be a way to make it work again, since its been working for over a month
you could get in contact with atlas
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?
by specifying the wanted version in your requirements.txt
this is what i have there:
but its not installing that version
you have a different version set elsewhere
or you haven't pushed those changes
thats crazy
it works now
it was legit just the version of that
thank you a lot for your time
interesting, well my apologies for sending you in the wrong direction, it was really looking like an IP ban from atlas
dont worry, mongo support couldnt even help aswell
I don't think there's anyone who could have helped with such an obscure cause of this issue
yeah it was weird
but happy you found a solution!