Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Add support to socket timeout, health check and keepalive #735

Closed
guoyiang opened this issue Apr 16, 2020 · 5 comments
Closed

Add support to socket timeout, health check and keepalive #735

guoyiang opened this issue Apr 16, 2020 · 5 comments
Labels
enhancement help wanted need investigation Need to look into described issue. resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.

Comments

@guoyiang
Copy link

guoyiang commented Apr 16, 2020

Hello,

When TCP connection lost without proper disconnection, existing redis connection may become broken and the next request may take a long time before it reaches system default socket timeout, which is around ~15 mins with default linux config ( https://stackoverflow.com/questions/20403118/tcp-ceases-retransmissions-before-reaching-the-default-of-15-attempts-after-phy ).
In this situation, redis operation will be blocked for a long time before an exception is thrown. This is observed in 1.3.1

  File "/home/bolt/.local/lib/python3.8/site-packages/example-0.0.0-py3.8.egg/example/registry.py", line 63, in get_redis
    get_redis= await self.redis_client.smembers(key)
  File "/home/bolt/.local/lib/python3.8/site-packages/aioredis/connection.py", line 186, in _read_data
    obj = await self._reader.readobj()
  File "/home/bolt/.local/lib/python3.8/site-packages/aioredis/stream.py", line 102, in readobj
    await self._wait_for_data('readobj')
  File "/usr/local/lib/python3.8/asyncio/streams.py", line 517, in _wait_for_data
    await self._waiter
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 846, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
TimeoutError: [Errno 110] Operation timed out

With issue #184 , connection timeout is added. It would be nice to support socket timeout, socket keepalive and health check to better handle connection loss.

Thanks!

@ppd0705
Copy link

ppd0705 commented Jul 16, 2020

i met the same problem when i use redis pool execute some command, it blocked。hope add timeout option too

@luisdamora
Copy link

I have the same error, it is related to the keepalive in the server configuration

@seandstewart seandstewart added enhancement help wanted need investigation Need to look into described issue. labels Nov 14, 2020
@seandstewart
Copy link
Collaborator

@guoyiang -

Thank you for your submission! Would you be willing to submit proposed implementation in a PR? This would be a great addition to the library.

@Andrew-Chen-Wang
Copy link
Collaborator

Andrew-Chen-Wang commented Nov 15, 2020

@seandstewart I like copying others' code, so this is a perfect place to copy from: redis-py implements it in the exact same way we should: https://github.com/andymccurdy/redis-py/blob/8c176cdc7f36e2cbcd3254768766035a7b7cd8b3/redis/connection.py#L589-L593

We would add this kind of code (not the same but...) in aioredis.connection: https://github.com/aio-libs/aioredis/blob/f5907fa8631a6f36684e081ec78e4d9267c6a992/aioredis/connection.py#L128-L143

Passing in the methods would be the same as passing in timeout (for connection timeout) in create_redis or pool conn.

@seandstewart
Copy link
Collaborator

This issue should be resolved as of #891 - please feel free to pull in the latest master and test to ensure this is the case.

@seandstewart seandstewart added the resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version. label Mar 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement help wanted need investigation Need to look into described issue. resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.
Projects
None yet
Development

No branches or pull requests

5 participants