Skip to content

Commit

Permalink
Fix: VmCache did not call the API via unix socket
Browse files Browse the repository at this point in the history
Instead, it tried using TCP calls on localhost:80.

Solution: Detect if `settings.API_UNIX_SOCKET` is set and use it when available.
  • Loading branch information
hoh committed Jul 10, 2023
1 parent 8aa9e6f commit 74e39b5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/aleph/sdk/vm/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ def __init__(
session: Optional[aiohttp.ClientSession] = None,
connector_url: Optional[AnyHttpUrl] = None,
):
self.session = session or aiohttp.ClientSession(base_url=connector_url)
"""Initialize a connection to the cache.
Requests use HTTP and default to using `settings.API_UNIX_SOCKET` with the
hostname `settings.API_HOST`.
Pass a custom `session` object for development and custom deployments.
"""
if settings.API_UNIX_SOCKET:
connector = aiohttp.UnixConnector(path=settings.API_UNIX_SOCKET)
else:
connector = None

self.session = session or aiohttp.ClientSession(
base_url=connector_url, connector=connector
)
self.cache = {}
self.api_host = connector_url if connector_url else settings.API_HOST

Expand Down

0 comments on commit 74e39b5

Please sign in to comment.