Django Channels Tutorial - Redis timeout error

I'm working my way through the Django channels tutorial. Everything is working perfectly until I make the changes for the "Enable a channel layer." When I try to open a chatroom I get the error, "redis.exceptions.TimeoutError: Timeout reading from 127.0.0.1:6379". I get a couple messages that makes it look like it's trying but then it times out after a couple seconds.

HTTP GET /chat/lobby/ 200 [0.01, 127.0.0.1:42272]
WebSocket HANDSHAKING /ws/chat/lobby/ [127.0.0.1:42288]
WebSocket CONNECT /ws/chat/lobby/ [127.0.0.1:42288]
Exception inside application: Timeout reading from localhost:6379
Traceback (most recent call last):
  File "/proj_root/.venv/lib/python3.12/site-packages/redis/asyncio/connection.py", line 783, in read_response
    response = await self._parser.read_response(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/redis/_parsers/resp3.py", line 185, in read_response
    response = await self._read_response(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/redis/_parsers/resp3.py", line 197, in _read_response
    raw = await self._readline()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/redis/_parsers/base.py", line 578, in _readline
    data = await self._stream.readline()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/streams.py", line 568, in readline
    line = await self.readuntil(sep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/streams.py", line 660, in readuntil
    await self._wait_for_data('readuntil')
  File "/usr/lib/python3.12/asyncio/streams.py", line 545, in _wait_for_data
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/proj_root/.venv/lib/python3.12/site-packages/redis/asyncio/connection.py", line 782, in read_response
    async with async_timeout(read_timeout):
  File "/usr/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/proj_root/.venv/lib/python3.12/site-packages/django/contrib/staticfiles/handlers.py", line 101, in __call__
    return await self.application(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/routing.py", line 48, in __call__
    return await application(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/security/websocket.py", line 37, in __call__
    return await self.application(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/sessions.py", line 44, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/sessions.py", line 261, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/auth.py", line 185, in __call__
    return await super().__call__(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/middleware.py", line 24, in __call__
    return await self.inner(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/routing.py", line 118, in __call__
    return await application(
           ^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/consumer.py", line 95, in app
    return await consumer(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/consumer.py", line 58, in __call__
    await await_many_dispatch(
  File "/proj_root/.venv/lib/python3.12/site-packages/channels/utils.py", line 57, in await_many_dispatch
    await task
redis.exceptions.TimeoutError: Timeout reading from localhost:6379
WebSocket DISCONNECT /ws/chat/lobby/ [127.0.0.1:42288]

There is a part at this stage to ensure "that the channel layer can communicate with Redis." This is successful, but it fails from the webpage. Based on this test, it appears that the Redis is running and connecting in the test case. Why is it failing for the webpage?

Вернуться на верх