Reputation: 925
I've a fairly simple django-channels/daphne/asgi/redis app. The app never has any problem when using chrome but fails miserably when we use firefox (latest version ~ 60). I currently have the following error:
api_1 | 2018-06-12 16:02:24,378 INFO In the connect method
api_1 | xxxxxx:41647 - - [12/Jun/2018:16:02:24] "WSCONNECT /updates/" - -
api_1 | 2018-06-12 16:02:25,049 ERROR Exception inside application: [Errno -2] Name or service not known
api_1 | File "/usr/local/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__
api_1 | await await_many_dispatch([receive, self.channel_receive], self.dispatch)
api_1 | File "/usr/local/lib/python3.6/site-packages/channels/utils.py", line 48, in await_many_dispatch
api_1 | await dispatch(result)
api_1 | File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 110, in __call__
api_1 | return await asyncio.wait_for(future, timeout=None)
api_1 | File "/usr/local/lib/python3.6/asyncio/tasks.py", line 339, in wait_for
api_1 | return (yield from fut)
api_1 | File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
api_1 | result = self.fn(*self.args, **self.kwargs)
api_1 | File "/usr/local/lib/python3.6/site-packages/channels/db.py", line 13, in thread_handler
api_1 | return super().thread_handler(loop, *args, **kwargs)
api_1 | File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 125, in thread_handler
api_1 | return self.func(*args, **kwargs)
api_1 | File "/usr/local/lib/python3.6/site-packages/channels/consumer.py", line 99, in dispatch
api_1 | handler(message)
api_1 | File "/usr/local/lib/python3.6/site-packages/channels/generic/websocket.py", line 19, in websocket_connect
api_1 | self.connect()
api_1 | File "./flypoll/consumers.py", line 146, in connect
api_1 | async_to_sync(self.channel_layer.group_add)("flypoll_socket_clients", self.channel_name)
api_1 | File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 64, in __call__
api_1 | return call_result.result()
api_1 | File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 432, in result
api_1 | return self.__get_result()
api_1 | File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
api_1 | raise self._exception
api_1 | File "/usr/local/lib/python3.6/site-packages/asgiref/sync.py", line 78, in main_wrap
api_1 | result = await self.awaitable(*args, **kwargs)
api_1 | File "/usr/local/lib/python3.6/site-packages/channels_redis/core.py", line 283, in group_add
api_1 | async with self.connection(self.consistent_hash(group)) as connection:
api_1 | File "/usr/local/lib/python3.6/site-packages/channels_redis/core.py", line 403, in __aenter__
api_1 | self.conn = await aioredis.create_redis(**self.kwargs)
api_1 | File "/usr/local/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 174, in create_redis
api_1 | loop=loop)
api_1 | File "/usr/local/lib/python3.6/site-packages/aioredis/connection.py", line 107, in create_connection
api_1 | timeout, loop=loop)
api_1 | File "/usr/local/lib/python3.6/asyncio/tasks.py", line 339, in wait_for
api_1 | return (yield from fut)
api_1 | File "/usr/local/lib/python3.6/site-packages/aioredis/stream.py", line 19, in open_connection
api_1 | lambda: protocol, host, port, **kwds)
api_1 | File "/usr/local/lib/python3.6/asyncio/base_events.py", line 734, in create_connection
api_1 | infos = f1.result()
api_1 | File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
api_1 | result = self.fn(*self.args, **self.kwargs)
api_1 | File "/usr/local/lib/python3.6/socket.py", line 745, in getaddrinfo
api_1 | for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
api_1 | [Errno -2] Name or service not known
It says there is a problem with connect method but the connect method is as follows:
def connect(self):
"""
standard connect handler, accepts the connection, and sets up some basic parameters
:return:
"""
logging.info("In the connect method")
self.accept()
async_to_sync(self.channel_layer.group_add)("flypoll_socket_clients", self.channel_name)
The app is dockerized and is hosted on ec2. The redis, python, django are dockerized too. I've updated the modules (asgiref, txaio, twisted, channels, daphne etc) to latest versions but i'm not able to get rid of this.
What could be wrong?
Upvotes: 3
Views: 1844
Reputation: 11943
It looks like your django container can't access redis.
In your django settings you must have something like this :
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [('[redis-host-here]', 6379)], # REPLACE redis host here
},
},
}
And that host must be accessible from your django container
Upvotes: 2