EGA-archive / beacon2-ri-api

Beacon v2 Reference Implementation (API)
Apache License 2.0
15 stars 37 forks source link

Beacon container does not connect to mongo container #92

Closed jdylan closed 6 months ago

jdylan commented 2 years ago

Expected Behavior

When following the instructions in the README the beacon container should be able to access the mongo container with dummy data.

Current Behavior

The beacon server times out, because it cannot establish a connection to the mongo db - below from the logs:

beacon  | [aiohttp.server][ERROR ] (L405) Error handling request
beacon  | Traceback (most recent call last):
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
beacon  |     resp = await request_handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
beacon  |     resp = await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
beacon  |     return await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 108, in impl
beacon  |     return await handler(request)
beacon  |   File "/beacon/beacon/response/middlewares.py", line 46, in error_middleware
beacon  |     return await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp_session/__init__.py", line 154, in factory
beacon  |     response = await handler(request)
beacon  |   File "/beacon/beacon/request/handlers.py", line 49, in wrapper
beacon  |     entity_schema, count, records = db_fn(entry_id, qparams)
beacon  |   File "/beacon/beacon/db/g_variants.py", line 105, in get_variants
beacon  |     count = get_count(client.beacon.genomicVariations, query)
beacon  |   File "/beacon/beacon/db/utils.py", line 34, in get_count
beacon  |     return collection.count_documents(query)
beacon  |   File "/usr/local/lib/python3.10/site-packages/pymongo/collection.py", line 1622, in count_documents
beacon  |     return self.__database.client._retryable_read(
beacon  |   File "/usr/local/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1350, in _retryable_read
beacon  |     server = self._select_server(read_pref, session, address=address)
beacon  |   File "/usr/local/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1176, in _select_server
beacon  |     server = topology.select_server(server_selector)
beacon  |   File "/usr/local/lib/python3.10/site-packages/pymongo/topology.py", line 247, in select_server
beacon  |     servers = self.select_servers(selector, server_selection_timeout, address)
beacon  |   File "/usr/local/lib/python3.10/site-packages/pymongo/topology.py", line 208, in select_servers
beacon  |     server_descriptions = self._select_servers_loop(selector, server_timeout, address)
beacon  |   File "/usr/local/lib/python3.10/site-packages/pymongo/topology.py", line 223, in _select_servers_loop
beacon  |     raise ServerSelectionTimeoutError(
beacon  | pymongo.errors.ServerSelectionTimeoutError: 127.0.0.1:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 628ca3f48630ba532b7c8aa6, topology_type: Unknown, servers: [<ServerDescription ('127.0.0.1', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('127.0.0.1:27017: [Errno 111] Connection refused')>]>
beacon  | [aiohttp.access][ INFO ] (L206) 172.21.0.1 [24/May/2022:09:23:38 +0000] "GET /api/g_variants/?start=9411499,9411644 HTTP/1.1" 500 245 "-" "HTTPie/3.2.1"

Possible Solution

This is possibly because the containers are on separate networks, the network allocation for each service has been commented out. I managed to get this to work by adding 'network_mode: host' to the docker-compose.yaml, though this has other implications.

Steps to Reproduce

Follow the deployment instructions exactly.

Context (Environment)

Deploying a Beacon V2 instance on an Ubuntu 20.04 VM under openstack.

delocalizer commented 2 years ago

I see the same issue — following this README.md with this compose file doesn't work out of the box because the networking is not set up right. @jdylan workaround is good as far as it goes.

anuradhawick commented 1 year ago

You can correct this by replacing database_host = '127.0.0.1' to database_host = 'mongo' in the beacon2-ri-api/deploy/conf.py file. I guess the network interfacing does not really happen via the local host. Your docker setup might be using a different private network configuration.

Anyway, this is how I resolved this issue.