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

Đang mở Phù hợp với người mới
#1,569 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #1571 của @Sauvi72 — đã đóng, không merge

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
django, python, redis
Lĩnh vực
backend, testing

Hướng nghiên cứu

Mở tests/openwisp2/settings.py và đọc khối CHANNEL_LAYERS ở dòng 106-112; bản sửa là chuyển chuỗi host đơn giản {REDIS_URL}/7 sang dạng dict với socket_timeout được đặt thành None. Hãy so sánh với thay đổi tương tự đã được thực hiện trong openwisp-notifications (commit bb156cf71) trước khi chỉnh sửa. Để xác minh, hãy cài redis>=8.0.0 và channels_redis, khởi động Redis cục bộ, chạy python tests/manage.py runserver, và xác nhận rằng kết nối WebSocket không còn đóng với mã 1011 sau ~5 giây.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
800
Fork
354
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
15

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openwisp/openwisp-controller

Tất cả issue của openwisp/openwisp-controller

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.