[bug] Test project RedisChannelLayer times out after 5s with redis-py 8

Aperta Adatta ai principianti
#1,569 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #1571 di @Sauvi72 — chiusa senza merge

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
django, python, redis
Ambito
backend, testing

Direzione di ricerca

Apri tests/openwisp2/settings.py e leggi il blocco CHANNEL_LAYERS alle righe 106-112; la correzione consiste nel passare dalla stringa host semplice {REDIS_URL}/7 alla forma dict con socket_timeout impostato a None. Confronta con la stessa modifica già effettuata in openwisp-notifications (commit bb156cf71) prima di modificare. Per verificare, installa redis>=8.0.0 e channels_redis, avvia un Redis locale, esegui python tests/manage.py runserver e conferma che una connessione WebSocket non si chiude più con codice 1011 dopo ~5 secondi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
In tests/openwisp2/settings.py (lines 106-112), when not TESTING, CHANNEL_LAYERS configures channels_redis.core.RedisChannelLayer with a plain Redis URL string:

if not TESTING:
    CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "channels_redis.core.RedisChannelLayer",
            "CONFIG": {"hosts": [f"{REDIS_URL}/7"]},
        }
    }

Starting with redis-py 8.0.0, the default socket timeout is 5 seconds. Because channels_redis blocks on BZPOPMIN for 5 seconds while waiting for messages on empty channels (see django/channels_redis#422), RedisChannelLayer.receive() raises redis.exceptions.TimeoutError: Timeout reading from ... after 5 seconds and Daphne closes active WebSocket connections with close code 1011.

This is the same redis-py 8 channel layer timeout issue already fixed in openwisp-notifications (bb156cf71) and reported in openwisp/openwisp-firmware-upgrader#517.

Steps To Reproduce

  1. Install test dependencies (pip install -r requirements-test.txt) with redis>=8.0.0 and channels_redis and start a local Redis server.
  2. Run the test project (python tests/manage.py runserver).
  3. Open a page using a WebSocket consumer backed by RedisChannelLayer (or call await RedisChannelLayer(hosts=["redis://localhost:6379/7"]).receive(channel) on an empty channel).
  4. Observe redis.exceptions.TimeoutError / WebSocket close code 1011 after ~5 seconds.

Expected behavior
WebSocket connections remain open while waiting for channel messages. Updating the host configuration in tests/openwisp2/settings.py to:

"CONFIG": {
    "hosts": [{"address": f"{REDIS_URL}/7", "socket_timeout": None}],
}

prevents the 5-second BZPOPMIN socket timeout while preserving Redis channel layer behavior.

System Information:

  • Branch: master
  • File: tests/openwisp2/settings.py
  • Affected dependency: redis-py >= 8.0.0 with channels_redis
Lingua principale
Python
Stelle
800
Fork
354
Merge medio
1g 8h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openwisp/openwisp-controller

Tutte le issue di openwisp/openwisp-controller

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.