Mongodb ServerSelectionTimeoutError

Hi
I am trying to connect to MongoDB on mongodb atlas. The tutor application is running on an ec2 instance. In the mongodb atlas metrics, I can see the connections being made, but still leading to this error.
Im using tutor version 13.1.0.
Have configured mongodb with below configs:

tutor config save --set RUN_MONGODB=false \
                            --set MONGODB_HOST="mongodb://<username>:<password>@cluster0-shard-00-00.kdqoq.mongodb.net:27017,cluster0-shard-00-01.kdqoq.mongodb.net:27017,cluster0-shard-00-02.kdqoq.mongodb.net:27017/edxapp?ssl=true&replicaSet=atlas-vpw4f2-shard-0&authSource=admin&retryWrites=true&w=majority"  \
                            --set MONGODB_PORT=27017 \
                            --set MONGODB_DATABASE="edxapp"

While importing the democourse(tutor local importdemocourse), Iā€™m getting the following error:

2022-05-07 06:13:34,739 WARNING 15 [root] [user None] [ip None] mixins.py:518 - XBlock <class 'xblock.internal.DiscussionXBlockWithMixins'> does not contain field url_name
2022-05-07 06:13:34,755 WARNING 15 [root] [user None] [ip None] mixins.py:518 - XBlock <class 'xblock.internal.DiscussionXBlockWithMixins'> does not contain field url_name
2022-05-07 06:13:34,770 WARNING 15 [root] [user None] [ip None] mixins.py:518 - XBlock <class 'xblock.internal.DiscussionXBlockWithMixins'> does not contain field url_name
2022-05-07 06:13:34,920 INFO 15 [xmodule.modulestore.xml] [user None] [ip None] xml.py:529 - Course import None: Done with courselike import from ../edx-demo-course
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/mongodb_proxy.py", line 55, in wrapper
    return func(*args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/collection.py", line 1273, in find_one
    for result in cursor.limit(-1):
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1156, in next
    if len(self.__data) or self._refresh():
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1050, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1810, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1763, in __start_session
    server_session = self._get_server_session()
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1796, in _get_server_session
    return self._topology.get_server_session()
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/topology.py", line 482, in get_server_session
    self._select_servers_loop(
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/topology.py", line 208, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: connection closed

I manually added the following configs in ~/.local/share/tutor/env/apps/openedx/settings/cms/production.py and restarted (tutor local restart), issues seemed to be fixed.

mongodb_parameters['replicaSet'] = 'atlas-vpw4f2-shard-0'
mongodb_parameters['authsource'] = 'admin'

The MongoDB parameters generated were:

mongodb_parameters = {
    "host": "mongodb://<username>:<password>@cluster0-shard-00-00.kdq.mongodb.net:27017,cluster0-shard-00-01.kdq.mongodb.net:27017,cluster0-shard-00-02.kdq.mongodb.net:27017/?ssl=true&replicaSet=atlas-v-shard-0&authSource=admin&retryWrites=true&w=majority>
    "port": 27017,
    "db": "openedx",
    "ssl": True,
    "user": None,
    "password": None,
}

@regis Is it possible to set these parameters using tutor config .. --set ..? Those parameters can be optional I guess.
I would be happy to open a PR for this if there are no other things might me messed because of these changes.

You can do it using a plugin, take a look here: plugin-development-tutorial.

1 Like

Got it. Thanks @erickhgm .

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.