r/djangolearning • u/throwaway_4534865 • 13h ago
I Need Help - Troubleshooting Tutorial Part 2: Implement a Chat Server
I'm following along the django channels tutorial and I'm running into a timeout error that I don't understand. I have everything setup as shown in the tutorial and it works for 5 seconds. If I open a page to a chatroom and constantly send a message every 5 seconds or less, the connection will remain connected. I can open a second window and send messages from the first window to the second, or vise-versa. However, if I stop sending messages for more than 5 seconds, there is a timeout error that occurs and I get an error message in the server terminal.
I have been looking online to see if I can find the issue but I'm at a bit of a loss what to look for.
The first error discusses Redis. I think Redis is just a easy way to create a database in memory for rapid access. If this is correct, I don't think Redis is the problem.
I don't think the problem is the result of my browser as I've tested with Chromium and Firefox with the same timeout results.
There are some error messages coming from django as well. I didn't see anything in the files setting a timeout parameter of any sort, let-alone one at 5 seconds.
I was modifying the tutorial code to learn a bit more and encountered this issue. I tried with a new server by simply copying and pasting the tutorial code directly to see if that would fix the problem but it didn't. (I can connect and send messages but a timeout error occurs after 5 seconds of idle time.) The tutorial doesn't talk about a timeout parameter being set. Technically speaking, the tutorial code does work and allows messages to be sent between 2 different windows so I think that it is probably working correctly. I would share the code, but I don't know what part to share.
Are there any configuration/parameter files where a timeout value is set?
Here is the error code that I receive:
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]
Edit: I found this github issue that has the same error message. I'm not seeing a fix though.
