ahopkins/sanic-session

Redis always “TimeoutError: [Errno 110] Connection timed out”

w38351479 opened this issue · 1 comments

Let it sit for a while to refresh the front-end page(about 15min),then redis timeout,but my redis-server set "timeout 0"。How should i deal with this problem?

#------------my code------------
from sanic import Sanic
import settings
import aioredis
from sanic_session import AIORedisSessionInterface, Session
......
app = Sanic("yunwei")

session = Session()
......
@app.before_server_start
async def before_server_start(app, loop):
app.ctx.redis_session = await aioredis.create_redis_pool(
(settings.REDIS_HOST, settings.REDIS_PORT), minsize=10, maxsize=20, loop=loop,
password=settings.REDIS_PASSWORD, db=settings.REDIS_SESSION_DB, encoding='utf-8'
)
session.init_app(app, interface=AIORedisSessionInterface(app.ctx.redis_session, expiry=settings.SESSION_EXPIRY))

@app.after_server_stop
async def after_server_stop(app, loop):
app.ctx.redis_session.close()
await app.ctx.redis_session.wait_closed()

#------------error message-----------
[2021-06-22 16:03:06 +0800] [18589] [ERROR] Exception occurred in one of response middleware handlers
Traceback (most recent call last):
File "/data/web/py39code/lib/python3.9/site-packages/sanic/request.py", line 183, in respond
response = await self.app._run_response_middleware(
File "/data/web/py39code/lib/python3.9/site-packages/sanic/app.py", line 1074, in _run_response_middleware
_response = await _response
File "/data/web/py39code/lib/python3.9/site-packages/sanic_session/init.py", line 41, in save_session
await self.interface.save(request, response)
File "/data/web/py39code/lib/python3.9/site-packages/sanic_session/base.py", line 150, in save
await self._delete_key(key)
File "/data/web/py39code/lib/python3.9/site-packages/sanic_session/aioredis.py", line 79, in _delete_key
await self.redis.delete(key)
File "/data/web/py39code/lib/python3.9/site-packages/aioredis/util.py", line 59, in wait_convert
result = await fut
File "/data/web/py39code/lib/python3.9/site-packages/aioredis/connection.py", line 186, in _read_data
obj = await self._reader.readobj()
File "/data/web/py39code/lib/python3.9/site-packages/aioredis/stream.py", line 102, in readobj
await self._wait_for_data('readobj')
File "/usr/local/python39/lib/python3.9/asyncio/streams.py", line 517, in _wait_for_data
await self._waiter
TimeoutError: [Errno 110] Connection timed out

xen commented

Probably your redis is down