Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ConnectionError: Could not connect to `mongod #3073

Closed
4 tasks
masip85 opened this issue May 18, 2023 · 3 comments
Closed
4 tasks

[BUG] ConnectionError: Could not connect to `mongod #3073

masip85 opened this issue May 18, 2023 · 3 comments
Labels
bug Bug fixes

Comments

@masip85
Copy link

masip85 commented May 18, 2023

Instructions

System information

Container from image building Dockerfile in this project.

Commands to reproduce

Execute ipython (Jus as CMD of Dockerfile does)

docker build -t voxel51/fiftyone .
SHARED_DIR=/mnt/b2drop/smartCity/
docker run --name fiftyone_cont --rm -v ${SHARED_DIR}:/fiftyone -p 5151:5151 -it voxel51/fiftyone

Describe the problem

Doesn't import fiftyone library. Error appears. See below

Code to reproduce issue

import fiftyone as fo

Other info/logs


In [4]: import fiftyone as fo
---------------------------------------------------------------------------
ServerSelectionTimeoutError               Traceback (most recent call last)
File /usr/local/lib/python3.8/dist-packages/fiftyone/core/odm/database.py:286, in _validate_db_version(config, client)
    285 try:
--> 286     version = Version(client.server_info()["version"])
    287 except Exception as e:

File /usr/local/lib/python3.8/dist-packages/pymongo/mongo_client.py:1805, in MongoClient.server_info(self, session)
   1794 """Get information about the MongoDB server we're connected to.
   1795 
   1796 :Parameters:
   (...)
   1801    Added ``session`` parameter.
   1802 """
   1803 return cast(
   1804     dict,
-> 1805     self.admin.command(
   1806         "buildinfo", read_preference=ReadPreference.PRIMARY, session=session
   1807     ),
   1808 )

File /usr/local/lib/python3.8/dist-packages/pymongo/_csot.py:105, in apply.<locals>.csot_wrapper(self, *args, **kwargs)
    104             return func(self, *args, **kwargs)
--> 105 return func(self, *args, **kwargs)

File /usr/local/lib/python3.8/dist-packages/pymongo/database.py:805, in Database.command(self, command, value, check, allowable_errors, read_preference, codec_options, session, comment, **kwargs)
    804     read_preference = (session and session._txn_read_preference()) or ReadPreference.PRIMARY
--> 805 with self.__client._socket_for_reads(read_preference, session) as (
    806     sock_info,
    807     read_preference,
    808 ):
    809     return self._command(
    810         sock_info,
    811         command,
   (...)
    818         **kwargs,
    819     )

File /usr/local/lib/python3.8/dist-packages/pymongo/mongo_client.py:1296, in MongoClient._socket_for_reads(self, read_preference, session)
   1295 _ = self._get_topology()
-> 1296 server = self._select_server(read_preference, session)
   1297 return self._socket_from_server(read_preference, server, session)

File /usr/local/lib/python3.8/dist-packages/pymongo/mongo_client.py:1257, in MongoClient._select_server(self, server_selector, session, address)
   1256 else:
-> 1257     server = topology.select_server(server_selector)
   1258 return server

File /usr/local/lib/python3.8/dist-packages/pymongo/topology.py:272, in Topology.select_server(self, selector, server_selection_timeout, address)
    271 """Like select_servers, but choose a random server if several match."""
--> 272 server = self._select_server(selector, server_selection_timeout, address)
    273 if _csot.get_timeout():

File /usr/local/lib/python3.8/dist-packages/pymongo/topology.py:261, in Topology._select_server(self, selector, server_selection_timeout, address)
    260 def _select_server(self, selector, server_selection_timeout=None, address=None):
--> 261     servers = self.select_servers(selector, server_selection_timeout, address)
    262     if len(servers) == 1:

File /usr/local/lib/python3.8/dist-packages/pymongo/topology.py:223, in Topology.select_servers(self, selector, server_selection_timeout, address)
    222 with self._lock:
--> 223     server_descriptions = self._select_servers_loop(selector, server_timeout, address)
    225     return [self.get_server_by_address(sd.address) for sd in server_descriptions]

File /usr/local/lib/python3.8/dist-packages/pymongo/topology.py:238, in Topology._select_servers_loop(self, selector, timeout, address)
    237 if timeout == 0 or now > end_time:
--> 238     raise ServerSelectionTimeoutError(
    239         "%s, Timeout: %ss, Topology Description: %r"
    240         % (self._error_message(selector), timeout, self.description)
    241     )
    243 self._ensure_opened()

ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 6465fa245b2bf43049aff6dd, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused')>]>

The above exception was the direct cause of the following exception:

ConnectionError                           Traceback (most recent call last)
Cell In[4], line 1
----> 1 import fiftyone as fo

File /usr/local/lib/python3.8/dist-packages/fiftyone/__init__.py:25
     21 import fiftyone.constants as _foc
     23 __version__ = _foc.VERSION
---> 25 from fiftyone.__public__ import *
     27 import fiftyone.core.uid as _fou
     28 import fiftyone.core.logging as _fol

File /usr/local/lib/python3.8/dist-packages/fiftyone/__public__.py:15
     12 annotation_config = _foc.load_annotation_config()
     13 app_config = _foc.load_app_config()
---> 15 _foo.establish_db_conn(config)
     17 from .core.aggregations import (
     18     Aggregation,
     19     Bounds,
   (...)
     31     Values,
     32 )
     33 from .core.collections import SaveContext

File /usr/local/lib/python3.8/dist-packages/fiftyone/core/odm/database.py:214, in establish_db_conn(config)
    209         raise error
    211 _client = pymongo.MongoClient(
    212     **_connection_kwargs, appname=foc.DATABASE_APPNAME
    213 )
--> 214 _validate_db_version(config, _client)
    216 # Register cleanup method
    217 atexit.register(_delete_non_persistent_datasets_if_allowed)

File /usr/local/lib/python3.8/dist-packages/fiftyone/core/odm/database.py:289, in _validate_db_version(config, client)
    287 except Exception as e:
    288     if isinstance(e, ServerSelectionTimeoutError):
--> 289         raise ConnectionError("Could not connect to `mongod`") from e
    291     raise RuntimeError("Failed to validate `mongod` version") from e
    293 if config.database_validation and version < foc.MIN_MONGODB_VERSION:

ConnectionError: Could not connect to `mongod

What areas of FiftyOne does this bug affect?

  • [ X] App: FiftyOne application issue
  • Core: Core Python library issue
  • Server: FiftyOne server issue

Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the FiftyOne codebase?

  • Yes. I can contribute a fix for this bug independently
  • [X ] Yes. I would be willing to contribute a fix for this bug with guidance from the FiftyOne community
  • No. I cannot contribute a bug fix at this time
@masip85 masip85 added the bug Bug fixes label May 18, 2023
@glenn-jocher
Copy link
Contributor

+1

Seeing the same problem in Colab by just running import fiftyone

@brimoor
Copy link
Contributor

brimoor commented Aug 5, 2023

@glenn-jocher if you're running in Google Colab (or any other Ubuntu 22.04 machine), you must manually install the correct MongoDB version like so:

!pip install fiftyone
!pip install fiftyone-db-ubuntu2204

See also: #3321, #3236, #2900, #2737, #2480, #1988, #1803

@swheaton
Copy link
Contributor

swheaton commented Oct 7, 2023

closing

@swheaton swheaton closed this as completed Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

No branches or pull requests

4 participants