1

Iam trying to use django_redis for redis cache backend for Django. The app is working fine in development stage on the localhost. But after deployment on Heroku and using django_redis for redis cache The connection is getting reset and the page crashes with 500 internal server error

2021-10-29T12:10:20.450924+00:00 heroku[router]: at=info method=GET path="/" host=www.humaurtum-matrimony.com request_id=37a90921-
9d8d-46c6-9d6a-888d34fb1d01 fwd="42.106.161.10" dyno=web.1 connect=0ms service=2701ms status=500 bytes=5280 protocol=https
2021-10-29T12:10:20.447599+00:00 app[web.1]: 2021-10-29 17:40:18,010 ERROR    Internal Server Error: /
2021-10-29T12:10:20.447606+00:00 app[web.1]: Traceback (most recent call last):
2021-10-29T12:10:20.447607+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django_redis/cache.py", line 27
, in _decorator
2021-10-29T12:10:20.447608+00:00 app[web.1]: return method(self, *args, **kwargs)
2021-10-29T12:10:20.447608+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django_redis/cache.py", line 94
, in _get
2021-10-29T12:10:20.447609+00:00 app[web.1]: return self.client.get(key, default=default, version=version, client=client)
2021-10-29T12:10:20.447609+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django_redis/client/default.py"
, line 222, in get
2021-10-29T12:10:20.447609+00:00 app[web.1]: raise ConnectionInterrupted(connection=client) from e
2021-10-29T12:10:20.447610+00:00 app[web.1]: django_redis.exceptions.ConnectionInterrupted: Redis ConnectionError: Error while rea
ding from socket: (104, 'Connection reset by peer')
2021-10-29T12:10:20.447610+00:00 app[web.1]:
2021-10-29T12:10:20.447611+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-10-29T12:10:20.447611+00:00 app[web.1]:
2021-10-29T12:10:20.447612+00:00 app[web.1]: Traceback (most recent call last):
2021-10-29T12:10:20.447612+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.
py", line 34, in inner
2021-10-29T12:10:20.447613+00:00 app[web.1]: response = get_response(request)
2021-10-29T12:10:20.447614+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py",
line 115, in _get_response
2021-10-29T12:10:20.447614+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2021-10-29T12:10:20.447614+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py",
line 113, in _get_response
2021-10-29T12:10:20.447615+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2021-10-29T12:10:20.447615+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/views/generic/base.py",
line 71, in view
2021-10-29T12:10:20.447616+00:00 app[web.1]: return self.dispatch(request, *args, **kwargs)
2021-10-29T12:10:20.447616+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/decorators.py", li
ne 43, in _wrapper
2021-10-29T12:10:20.447616+00:00 app[web.1]: return bound_method(*args, **kwargs)
2021-10-29T12:10:20.447617+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/views/decorators/debug.p
y", line 76, in sensitive_post_parameters_wrapper
2021-10-29T12:10:20.447617+00:00 app[web.1]: return view(request, *args, **kwargs)
2021-10-29T12:10:20.447617+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/decorators.py", li
ne 43, in _wrapper
2021-10-29T12:10:20.447617+00:00 app[web.1]: return bound_method(*args, **kwargs)
2021-10-29T12:10:20.447618+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/decorators.py", li
ne 130, in _wrapped_view
2021-10-29T12:10:20.447618+00:00 app[web.1]: response = view_func(request, *args, **kwargs)
2021-10-29T12:10:20.447618+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/decorators.py", li
ne 43, in _wrapper
2021-10-29T12:10:20.447618+00:00 app[web.1]: return bound_method(*args, **kwargs)
2021-10-29T12:10:20.447619+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/views/decorators/cache.p
y", line 44, in _wrapped_view_func
2021-10-29T12:10:20.447619+00:00 app[web.1]: response = view_func(request, *args, **kwargs)
2021-10-29T12:10:20.447619+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/auth/views.py",
line 63, in dispatch
2021-10-29T12:10:20.447619+00:00 app[web.1]: return super().dispatch(request, *args, **kwargs)
2021-10-29T12:10:20.447620+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/views/generic/base.py",
line 97, in dispatch
2021-10-29T12:10:20.447620+00:00 app[web.1]: return handler(request, *args, **kwargs)
2021-10-29T12:10:20.447620+00:00 app[web.1]: File "./member/views.py", line 243, in get
2021-10-29T12:10:20.447620+00:00 app[web.1]: return render(request, 'member/login_new.html', context)
2021-10-29T12:10:20.447621+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/shortcuts.py", line 19,
in render
2021-10-29T12:10:20.447621+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2021-10-29T12:10:20.447621+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader.py", lin
e 62, in render_to_string
2021-10-29T12:10:20.447622+00:00 app[web.1]: return template.render(context, request)
2021-10-29T12:10:20.447622+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/backends/django
.py", line 61, in render
2021-10-29T12:10:20.447622+00:00 app[web.1]: return self.template.render(context)
2021-10-29T12:10:20.447622+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line
171, in render
2021-10-29T12:10:20.447623+00:00 app[web.1]: return self._render(context)
2021-10-29T12:10:20.447623+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line
163, in _render
2021-10-29T12:10:20.447623+00:00 app[web.1]: return self.nodelist.render(context)
2021-10-29T12:10:20.447623+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line
936, in render
2021-10-29T12:10:20.447624+00:00 app[web.1]: bit = node.render_annotated(context)
2021-10-29T12:10:20.447624+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line
903, in render_annotated
2021-10-29T12:10:20.447624+00:00 app[web.1]: return self.render(context)
2021-10-29T12:10:20.447625+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/templatetags/cache.py",
line 45, in render
2021-10-29T12:10:20.447625+00:00 app[web.1]: value = fragment_cache.get(cache_key)
2021-10-29T12:10:20.447629+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django_redis/cache.py", line 87
, in get
2021-10-29T12:10:20.447630+00:00 app[web.1]: value = self._get(key, default, version, client)
2021-10-29T12:10:20.447630+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django_redis/cache.py", line 34
, in _decorator
2021-10-29T12:10:20.447630+00:00 app[web.1]: raise e.__cause__
2021-10-29T12:10:20.447630+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django_redis/client/default.py"
, line 220, in get
2021-10-29T12:10:20.447631+00:00 app[web.1]: value = client.get(key)
2021-10-29T12:10:20.447631+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/client.py", line 1606, in
 get
2021-10-29T12:10:20.447632+00:00 app[web.1]: return self.execute_command('GET', name)
2021-10-29T12:10:20.447632+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/client.py", line 898, in
execute_command
2021-10-29T12:10:20.447632+00:00 app[web.1]: conn = self.connection or pool.get_connection(command_name, **options)
2021-10-29T12:10:20.447632+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/connection.py", line 1192
, in get_connection
2021-10-29T12:10:20.447633+00:00 app[web.1]: connection.connect()
2021-10-29T12:10:20.447633+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/connection.py", line 567,
 in connect
2021-10-29T12:10:20.447634+00:00 app[web.1]: self.on_connect()
2021-10-29T12:10:20.447634+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/connection.py", line 643,
 in on_connect
2021-10-29T12:10:20.447634+00:00 app[web.1]: auth_response = self.read_response()
2021-10-29T12:10:20.447634+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/connection.py", line 739,
 in read_response
2021-10-29T12:10:20.447635+00:00 app[web.1]: response = self._parser.read_response()
2021-10-29T12:10:20.447635+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/connection.py", line 470,
 in read_response
2021-10-29T12:10:20.447635+00:00 app[web.1]: self.read_from_socket()
2021-10-29T12:10:20.447635+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/redis/connection.py", line 453,
 in read_from_socket
2021-10-29T12:10:20.447636+00:00 app[web.1]: (ex.args,))
2021-10-29T12:10:20.447636+00:00 app[web.1]: redis.exceptions.ConnectionError: Error while reading from socket: (104, 'Connection
reset by peer')
2021-10-29T12:10:20.448350+00:00 app[web.1]: 2021-10-29 17:40:20,448 DEBUG    HTTP 500 response started for ['10.1.61.20', 31465]
2021-10-29T12:10:20.449096+00:00 app[web.1]: 2021-10-29 17:40:20,448 DEBUG    HTTP close for ['10.1.61.20', 31465]
2021-10-29T12:10:20.449355+00:00 app[web.1]: 2021-10-29 17:40:20,449 INFO     "10.1.61.20" - - [08/Jan/1970:14:23:33 +0000] "GET /
 HTTP/1.1" 500 5052 "https://www.humaurtum-matrimony.com/" "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, li
ke Gecko) Chrome/94.0.4606.61 Safari/537.36"
2021-10-29T12:10:20.449533+00:00 app[web.1]: 2021-10-29 17:40:20,449 DEBUG    HTTP response complete for ['10.1.61.20', 31465]
2021-10-29T12:10:20.449615+00:00 app[web.1]: 10.1.61.20:31465 - - [29/Oct/2021:17:40:20] "GET /" 500 5052
^CTerminate batch job (Y/N)? y

The settings.py has the following CACHE setting

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",     
        "LOCATION": 'redis://:[email protected]:xx',
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}

Kindly suggest how to overcome the issue. Thanks

1 Answer 1

1

I encountered the error due to using 'REDIS_URL'

The simple answer, as confirmed by Heroku, is to use 'REDIS_TLS_URL'!

the settings for redis_cache will be as follows, as given in the docs:

import os
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": os.environ.get('REDIS_TLS_URL'),
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "CONNECTION_POOL_KWARGS": {
                "ssl_cert_reqs": None
            },
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.