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

オープン 初心者向け
#1,569 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #1571 @Sauvi72 による — マージされずにクローズ

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
django, python, redis
領域
backend, testing

調査の方向性

tests/openwisp2/settings.py を開き、106-112 行目の CHANNEL_LAYERS ブロックを読んでください。修正は、単純な {REDIS_URL}/7 ホスト文字列を、socket_timeout を None に設定した dict 形式に切り替えることです。編集する前に、openwisp-notifications ですでに行われている同じ変更(commit bb156cf71)と比較してください。確認するには、redis>=8.0.0 と channels_redis をインストールし、ローカルの Redis を起動し、python tests/manage.py runserver を実行して、WebSocket 接続が ~5 秒後にコード 1011 で閉じなくなったことを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Python
スター
800
フォーク
354
平均マージ
1日 8時間
マージ済み PR(30日)
15

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openwisp/openwisp-controller のほかの issue

openwisp/openwisp-controller の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。