diff --git a/src/aleph/vm/guest_api/__main__.py b/src/aleph/vm/guest_api/__main__.py index 8000d52b..e5b89ebe 100644 --- a/src/aleph/vm/guest_api/__main__.py +++ b/src/aleph/vm/guest_api/__main__.py @@ -24,8 +24,15 @@ async def get_redis(address: str = REDIS_ADDRESS) -> aioredis.Redis: global _redis - if _redis is None: + # Ensure the redis connection is still up before returning it + if _redis: + try: + await _redis.ping() + except aioredis.ConnectionClosedError: + _redis = None + if not _redis: _redis = await aioredis.create_redis(address=address) + return _redis