2

I have a Django app using DgangoChannels, Djangochannelrestframework. It establishes a websocket connection with ReactJS frontend. As channel layers I use Redis like that

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("redis", 6379)],
        },
    },
}

Redis and Django runs in docker. My redis docker setup is

  redis:
    image: "redis:7.0.4-alpine"
    command: redis-server
    ports:
      - "6379:6379"
    networks:
      - nginx_network

When I run my app on production server everything works for 5-8 hours. But after that period, if Django app trying to send a message via ws if falls with the error

ReadOnlyError at /admin/operations/operation/add/
READONLY You can't write against a read only replica.
Request Method: POST
Request URL:    http://62.84.123.168/admin/operations/operation/add/
Django Version: 3.2.12
Exception Type: ReadOnlyError
Exception Value:    
READONLY You can't write against a read only replica.
Exception Location: /usr/local/lib/python3.8/site-packages/channels_redis/core.py, line 673, in group_send
Python Executable:  /usr/local/bin/python
Python Version: 3.8.13
Python Path:    
['/opt/code',
 '/usr/local/bin',
 '/usr/local/lib/python38.zip',
 '/usr/local/lib/python3.8',
 '/usr/local/lib/python3.8/lib-dynload',
 '/usr/local/lib/python3.8/site-packages']
Server time:    Tue, 02 Aug 2022 08:23:18 +0300

I understand that it somehow connected with Redis replication, but no idea why if falls after period of time and how to fix it

Vishal Vasani
  • 647
  • 8
  • 16
Ivan
  • 121
  • 1
  • 9

1 Answers1

1

I have the same error, the possible solution is here

Fix by adding command to docker and disable the replica-read-only config, add this to your redis docker compose

command: redis-server --appendonly yes --replica-read-only no

then you could try to verify if the ​replica-read-only​ is disable using​redis-cli > config get replica-read-only​ command , if the result is no then it successful to disable.

exp3ct
  • 11
  • 2