WebSocket在升级Heroku Redis Django Channels应用程序版本后立即断开连接

wyyhbhjk  于 2022-10-31  发布在  Redis
关注(0)|答案(1)|浏览(160)

由于Heroku会弃用我的应用程序使用的Redis版本(5.0.12),我升级到了Redis版本6.2.3。
从那时起,WebSocket立即在我的客户端中触发onclose回调。

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

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

我的配置需要做什么改变,如果有的话,才能让新版本的Redis正常运行?
先谢谢你。

mnemlml8

mnemlml81#

这是一个老问题,但对于任何其他人面临类似的连接错误Heroku让你参考文档:
从Redis 6版本开始,爱好计划支持TLS和非加密连接。生产计划需要TLS连接。您必须在Redis客户端配置中启用TLS,才能连接到Redis 6数据库。更多信息,请参阅Heroku Data for Redis Security and Compliance。
所以换句话说,如果你的Redis示例在生产计划中,请确保你正确设置了TLS。
如果是这种情况,因为你使用的是Python/Django,你应该引用:https://devcenter.heroku.com/articles/connecting-heroku-redis#connecting-in-python

相关问题