Since Heroku will deprecate the version of Redis my app was using (5.0.12), I upgraded to Redis version 6.2.3.
Since then, the websocket immediately triggers the onclose
callback in my client. In the logs, I get this error message:
2021-06-21T18:18:20.761857+00:00 app[web.1]: 2021-06-21 18:18:20,761 ERROR [daphne.server] [asyncioreactor.py:290] - Exception inside application: [Errno 104] Connection reset by peer
2021-06-21T18:18:20.761866+00:00 app[web.1]: Traceback (most recent call last):
2021-06-21T18:18:20.761867+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels/sessions.py", line 183, in __call__
2021-06-21T18:18:20.761867+00:00 app[web.1]: return await self.inner(receive, self.send)
2021-06-21T18:18:20.761868+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels/middleware.py", line 41, in coroutine_call
2021-06-21T18:18:20.761868+00:00 app[web.1]: await inner_instance(receive, send)
2021-06-21T18:18:20.761868+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels/consumer.py", line 59, in __call__
2021-06-21T18:18:20.761869+00:00 app[web.1]: [receive, self.channel_receive], self.dispatch
2021-06-21T18:18:20.761869+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels/utils.py", line 58, in await_many_dispatch
2021-06-21T18:18:20.761870+00:00 app[web.1]: await task
2021-06-21T18:18:20.761870+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels/utils.py", line 50, in await_many_dispatch
2021-06-21T18:18:20.761871+00:00 app[web.1]: result = task.result()
2021-06-21T18:18:20.761871+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", line 435, in receive
2021-06-21T18:18:20.761871+00:00 app[web.1]: real_channel
2021-06-21T18:18:20.761872+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", line 490, in receive_single
2021-06-21T18:18:20.761872+00:00 app[web.1]: index, channel_key, timeout=self.brpop_timeout
2021-06-21T18:18:20.761872+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", line 330, in _brpop_with_clean
2021-06-21T18:18:20.761873+00:00 app[web.1]: async with self.connection(index) as connection:
2021-06-21T18:18:20.761873+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", line 835, in __aenter__
2021-06-21T18:18:20.761873+00:00 app[web.1]: self.conn = await self.pool.pop()
2021-06-21T18:18:20.761873+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/channels_redis/core.py", line 73, in pop
2021-06-21T18:18:20.761874+00:00 app[web.1]: conns.append(await aioredis.create_redis(**self.host, loop=loop))
2021-06-21T18:18:20.761886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/aioredis/commands/__init__.py", line 175, in create_redis
2021-06-21T18:18:20.761886+00:00 app[web.1]: loop=loop)
2021-06-21T18:18:20.761887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/aioredis/connection.py", line 133, in create_connection
2021-06-21T18:18:20.761887+00:00 app[web.1]: await conn.auth(password)
2021-06-21T18:18:20.761887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/aioredis/util.py", line 52, in wait_ok
2021-06-21T18:18:20.761887+00:00 app[web.1]: res = await fut
2021-06-21T18:18:20.761887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/aioredis/connection.py", line 186, in _read_data
2021-06-21T18:18:20.761888+00:00 app[web.1]: obj = await self._reader.readobj()
2021-06-21T18:18:20.761888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/aioredis/stream.py", line 102, in readobj
2021-06-21T18:18:20.761888+00:00 app[web.1]: await self._wait_for_data('readobj')
2021-06-21T18:18:20.761888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/asyncio/streams.py", line 473, in _wait_for_data
2021-06-21T18:18:20.761888+00:00 app[web.1]: await self._waiter
2021-06-21T18:18:20.761889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/asyncio/selector_events.py", line 814, in _read_ready__data_received
2021-06-21T18:18:20.761889+00:00 app[web.1]: data = self._sock.recv(self.max_size)
2021-06-21T18:18:20.761889+00:00 app[web.1]: ConnectionResetError: [Errno 104] Connection reset by peer
CHANNEL_LAYERS value in settings.py
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ['REDIS_URL']],
"symmetric_encryption_keys": [SECRET_KEY],
},
},
}
requirements.txt
aiohttp==3.6.2
aioredis==1.3.1
amqp==2.6.0
appdirs==1.4.3
asgi-redis==1.4.3
asgiref==3.2.7
async-timeout==3.0.1
atomicwrites==1.4.0
attrs==19.3.0
autobahn==20.4.3
Automat==20.2.0
autopep8==1.5.2
AWSIoTPythonSDK==1.4.7
billiard==3.6.3.0
CacheControl==0.12.6
cachetools==4.1.0
celery==4.4.6
certifi==2020.4.5.1
cffi==1.14.0
channels==2.4.0
channels-redis==2.4.2
chardet==3.0.4
colorama==0.4.3
constantly==15.1.0
contextlib2==0.6.0
cryptography==2.9.2
daphne==2.5.0
ddtrace==0.40.0
defusedxml==0.6.0
distlib==0.3.0
distro==1.4.0
dj-database-url==0.5.0
Django==3.0.6
django-braces==1.14.0
django-cors-headers==3.2.1
django-datadog-logger==0.3.2
django-filter==2.2.0
django-heroku==0.3.1
django-oauth-toolkit==1.3.2
django-rest-framework-social-oauth2==1.1.0
django-rest-passwordreset==1.1.0
djangorestframework==3.11.0
future==0.18.2
google-api-core==1.22.1
google-api-python-client==1.10.0
google-auth==1.20.1
google-auth-httplib2==0.0.4
google-auth-oauthlib==0.4.1
googleapis-common-protos==1.51.0
graphqlclient==0.2.4
gunicorn==20.0.4
hiredis==1.0.1
html5lib==1.0.1
httplib2==0.17.3
hyperlink==19.0.0
idna==2.8
importlib-metadata==1.6.0
incremental==17.5.0
intervaltree==3.0.2
ipaddr==2.2.0
JSON-log-formatter==0.3.0
kombu==4.6.11
lockfile==0.12.2
Markdown==3.2.2
more-itertools==8.2.0
msgpack==0.6.2
msgpack-python==0.5.6
multidict==4.7.6
mysql==0.0.2
mysqlclient==1.4.6
numpy==1.19.1
oauth2client==4.1.3
oauthlib==3.1.0
packaging==20.3
paho-mqtt==1.5.0
pandas==1.1.1
pep517==0.8.2
pluggy==0.13.1
progress==1.5
protobuf==3.13.0
psycopg2-binary==2.8.5
py==1.8.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.5.0
pycparser==2.20
pygsheets==2.0.3.1
PyHamcrest==2.0.2
PyJWT==1.7.1
pyOpenSSL==19.1.0
pyparsing==2.4.7
pytest==5.4.2
pytest-django==3.9.0
python-dateutil==2.8.1
python3-openid==3.1.0
pytoml==0.1.21
pytz==2020.1
redis==2.10.6
requests==2.22.0
requests-oauthlib==1.3.0
retrying==1.3.3
rsa==4.0
service-identity==18.1.0
six==1.14.0
social-auth-app-django==3.1.0
social-auth-core==3.3.3
sortedcontainers==2.2.2
sqlparse==0.3.1
stripe==2.54.0
tabulate==0.8.7
tenacity==6.2.0
Twisted==20.3.0
txaio==20.4.1
uritemplate==3.0.1
urllib3==1.25.9
vine==1.3.0
wcwidth==0.1.9
webencodings==0.5.1
websockets==8.1
whitenoise==5.0.1
xlrd==1.2.0
yarl==1.4.2
zipp==3.1.0
zope.interface==5.1.0
What needs to change in my configuration, if anything, to get the new version of Redis working?
Thanks in advance.
This is an old question but for anyone else facing similar connection errors on Heroku make you reference the docs:
So in other words make sure you are setting up TLS correctly if your Redis instance is on a production plan.
If this is the case, since you are using Python/Django you should reference: https://devcenter.heroku.com/articles/connecting-heroku-redis#connecting-in-python