channels existing site now disconnects/timeout

Some code that was working is now less working after a server rebuild, so new packages but same python and relevant configs.

WS works, but now it disconnects if it is idle for a few seconds.
I am guessing this is a clue:

videoteam@kas1:/srv/www/pib/pib$ sudo systemctl status pib-daphne.service
...
Sep 25 16:02:34 kas1 daphne[1129]: redis.exceptions.TimeoutError: Timeout reading from 127.0.0.1:6379

all the things are here, but there are a lot of things so feel free to ask me to dig up the specific details, like the real files off the server, not the ansible templates.

This indicates a problem with the redis connection, not the websocket connection. (Port 6379 is the standard redis port.)

What’s your redis configuration file? (Particularly the timeout and keepalive settings, but eyeball them all.)

What’s your CHANNEL_LAYERS setting?

Check for error messages in the redis log and syslog, along with other messages in the daphne log. (Check the complete log file don’t use systemctl or journalctl)

debian /etc/redis/redis.conf

tcp-keepalive 300
timeout 0

Sep 25 22:03:37 kas1 daphne[1129]: 2026-09-26 03:03:37,218 ERROR    Exception inside application: Timeout reading from 127.0.0.1:6379
Sep 25 22:03:37 kas1 daphne[1129]: Traceback (most recent call last):
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/redis/asyncio/connection.py", line 1286, in read_response
Sep 25 22:03:37 kas1 daphne[1129]:     response = await self._read_response_from_parser(
Sep 25 22:03:37 kas1 daphne[1129]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:     ...<2 lines>...
Sep 25 22:03:37 kas1 daphne[1129]:     )
Sep 25 22:03:37 kas1 daphne[1129]:     ^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/redis/asyncio/connection.py", line 1335, in _read_response_from_parser
Sep 25 22:03:37 kas1 daphne[1129]:     return await self._parser.read_response(
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:         disable_decoding=disable_decoding, push_request=push_request
Sep 25 22:03:37 kas1 daphne[1129]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:     )
Sep 25 22:03:37 kas1 daphne[1129]:     ^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/redis/_parsers/resp3.py", line 185, in read_response
Sep 25 22:03:37 kas1 daphne[1129]:     response = await self._read_response(
Sep 25 22:03:37 kas1 daphne[1129]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:         disable_decoding=disable_decoding, push_request=push_request
Sep 25 22:03:37 kas1 daphne[1129]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:     )
Sep 25 22:03:37 kas1 daphne[1129]:     ^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/redis/_parsers/resp3.py", line 197, in _read_response
Sep 25 22:03:37 kas1 daphne[1129]:     raw = await self._readline()
Sep 25 22:03:37 kas1 daphne[1129]:           ^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/redis/_parsers/base.py", line 587, in _readline
Sep 25 22:03:37 kas1 daphne[1129]:     data = await self._stream.readline()
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/usr/lib/python3.13/asyncio/streams.py", line 562, in readline
Sep 25 22:03:37 kas1 daphne[1129]:     line = await self.readuntil(sep)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/usr/lib/python3.13/asyncio/streams.py", line 677, in readuntil
Sep 25 22:03:37 kas1 daphne[1129]:     await self._wait_for_data('readuntil')
Sep 25 22:03:37 kas1 daphne[1129]:   File "/usr/lib/python3.13/asyncio/streams.py", line 539, in _wait_for_data
Sep 25 22:03:37 kas1 daphne[1129]:     await self._waiter
Sep 25 22:03:37 kas1 daphne[1129]: asyncio.exceptions.CancelledError
Sep 25 22:03:37 kas1 daphne[1129]: The above exception was the direct cause of the following exception:
Sep 25 22:03:37 kas1 daphne[1129]: Traceback (most recent call last):
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/redis/asyncio/connection.py", line 1283, in read_response
Sep 25 22:03:37 kas1 daphne[1129]:     async with timeout_context as active_timeout:
Sep 25 22:03:37 kas1 daphne[1129]:                ^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/usr/lib/python3.13/asyncio/timeouts.py", line 116, in __aexit__
Sep 25 22:03:37 kas1 daphne[1129]:     raise TimeoutError from exc_val
Sep 25 22:03:37 kas1 daphne[1129]: TimeoutError
Sep 25 22:03:37 kas1 daphne[1129]: During handling of the above exception, another exception occurred:
Sep 25 22:03:37 kas1 daphne[1129]: Traceback (most recent call last):
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/routing.py", line 48, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await application(scope, receive, send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/security/websocket.py", line 37, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await self.application(scope, receive, send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/sessions.py", line 44, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await self.inner(dict(scope, cookies=cookies), receive, send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/sessions.py", line 261, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await self.inner(wrapper.scope, receive, wrapper.send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/auth.py", line 185, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await super().__call__(scope, receive, send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/middleware.py", line 24, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await self.inner(scope, receive, send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/routing.py", line 118, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     return await application(
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:     ...<10 lines>...
Sep 25 22:03:37 kas1 daphne[1129]:     )
Sep 25 22:03:37 kas1 daphne[1129]:     ^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/consumer.py", line 95, in app
Sep 25 22:03:37 kas1 daphne[1129]:     return await consumer(scope, receive, send)
Sep 25 22:03:37 kas1 daphne[1129]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/consumer.py", line 58, in __call__
Sep 25 22:03:37 kas1 daphne[1129]:     await await_many_dispatch(
Sep 25 22:03:37 kas1 daphne[1129]:         [receive, self.channel_receive], self.dispatch
Sep 25 22:03:37 kas1 daphne[1129]:     )
Sep 25 22:03:37 kas1 daphne[1129]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/utils.py", line 57, in await_many_dispatch
Sep 25 22:03:37 kas1 daphne[1129]:     await task
Sep 25 22:03:37 kas1 daphne[1129]: redis.exceptions.TimeoutError: Timeout reading from 127.0.0.1:6379

root@kas1:/var/log/redis# less redis-server.log

1133:C 25 Sep 2026 04:17:50.327 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under l
ow memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/iss
ues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_me
mory=1' for this to take effect.
1133:C 25 Sep 2026 04:17:50.327 * Supervised by systemd. Please make sure you set appropriate values for TimeoutStartSec and TimeoutStopSe
c in your service unit.
1133:C 25 Sep 2026 04:17:50.327 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1133:C 25 Sep 2026 04:17:50.327 * Redis version=8.0.2, bits=64, commit=00000000, modified=0, pid=1133, just started
1133:C 25 Sep 2026 04:17:50.327 * Configuration loaded
1133:M 25 Sep 2026 04:17:50.328 * monotonic clock: POSIX clock_gettime
1133:M 25 Sep 2026 04:17:50.329 * Running mode=standalone, port=6379.
1133:M 25 Sep 2026 04:17:50.330 * Server initialized

I don’t have var/log/syslog - isn’t that now in journalctl ?

root@kas1:/var/log/redis# free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       1.6Gi        11Gi       8.4Mi       3.3Gi        13Gi
Swap:          6.0Gi          0B       6.0Gi

note - old server’s drive mounted under /mnt/sdb1, no change:

root@kas1:/var/log/redis# diff /etc/redis/redis.conf /mnt/sdb1/etc/redis/redis.conf

another note: a 2nd system that was based on my configs/python code is having the same problem:

Aug 26 11:37:48 tweed daphne[64042]:   File "/srv/www/pib/venv/lib/python3.13/site-packages/channels/utils.py", line 57, in await_many_di>
Aug 26 11:37:48 tweed daphne[64042]:     await task
Aug 26 11:37:48 tweed daphne[64042]: redis.exceptions.TimeoutError: Timeout reading from 127.0.0.1:6379

root@tweed:/var/log/redis# uptime 
 17:32:46 up 31 days,  6:26,  1 user,  load average: 0.35, 0.25, 0.20

This makes me think it is a regression in something installed from debian or pypi.

What version of the python redis library are you using? What versions of Django, Channels and Daphne? (I can see you’re using Python 3.13)

Do you know what version of redis was being used in the previous version (before the upgrade)?

(Yes, systemd-journald can be run without syslog - I’ve just never used a system configured that way)

This just in:

redis-py 8.0 (pulled in via the unpinned channels_redis dependency) changed the default socket_timeout from None to 5 s. channels_redis waits for websocket messages with a blocking BZPOPMIN that also lasts 5 s. The client therefore gives up at the moment Redis would have answered, and every websocket idle for 5 s is killed. Upstream issue: django/channels_redis#422. The maintainer’s recommended fix is this explicit setting.

tested on the other site, applying to my site now. will post results shortly.

Yep, that seemed to fix it.

“socket_timeout”: None

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            # socket_timeout must be None (or longer than the layer's 5 s
            # blocking receive): redis-py >= 8 defaults it to 5 s, which
            # kills every idle websocket consumer with "Timeout reading from
            # 127.0.0.1:6379". See django/channels_redis#422.
            "hosts": [{"address": "redis://127.0.0.1:6379", "socket_timeout": None}],
        },
    },
}

Thanks for taking the time to help, I hope this thread helps others that bump into this too.