Websocket connection doesn't work with redis cluster

I'm trying to establish a websocket connection but it doesn't seem to work due to my redis server which is a cluster from elasticache.

Here are the logs:

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/channels/consumer.py",>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     await handler(message)

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/channels/generic/webso>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     await self.connect()

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/shipninja/shipninja/shipninja/consumers.py", line 36, in>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     await self.channel_layer.group_add("inventory", self.channel_name)

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/channels_redis/core.py>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     await connection.zadd(group_key, {channel: time.time()})

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/redis/asyncio/client.p>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     conn = self.connection or await pool.get_connection(command_name, **optio>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/redis/asyncio/connecti>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     await self.ensure_connection(connection)

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/redis/asyncio/connecti>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     await connection.connect()

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:   File "/home/ubuntu/venv/lib/python3.10/site-packages/redis/asyncio/connecti>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]:     raise ConnectionError(self._error_message(e))

Feb 27 03:54:24 ip-172-31-40-162 python[12684]: redis.exceptions.ConnectionError: Error -2 connecting to rediss://clustercfg.>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]: Future exception was never retrieved

Feb 27 03:54:24 ip-172-31-40-162 python[12684]: future: <Future finished exception=gaierror(-2, 'Name or service not known')>

Feb 27 03:54:24 ip-172-31-40-162 python[12684]: socket.gaierror: [Errno -2] Name or service not known
Feb 27 03:54:24 ip-172-31-40-162 python[12684]: INFO:     connection open
Feb 27 03:54:24 ip-172-31-40-162 python[12684]: INFO:     connection closed

I thought this was a dns issue with my redis cluster but nslookup for the cluster endpoint worked fine.

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("rediss://clustercfg.rediscluster.m0rn9y.use1.cache.amazonaws.com", 6379)],
        },
    },
}
Back to Top