Skip to content

Infinity retry on the exception of max number of clients reached #2563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhuang42 opened this issue Jan 24, 2023 · 4 comments · Fixed by #3557
Closed

Infinity retry on the exception of max number of clients reached #2563

zhuang42 opened this issue Jan 24, 2023 · 4 comments · Fixed by #3557

Comments

@zhuang42
Copy link

zhuang42 commented Jan 24, 2023

Version: What redis-py and what redis version is the issue happening on?
redis-py: 3.5.3
redis: 6.0.10

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)
Python 3.8.7
OS: Ubuntu 20.04 x86/64

Description: Description of your issue, stack traces from errors and code that reproduces the issue

The redis-py keeps retrying in the redis.exceptions.ConnectionError: max number of clients reached, the worse thing is it keeps retrying in its exception handler which causes an infinity loop. The following logs are repeated hundreds of times.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 685, in check_health
    if nativestr(self.read_response()) != 'PONG':
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 739, in read_response
    response = self._parser.read_response()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 340, in read_response
    raise error
redis.exceptions.ConnectionError: max number of clients reached

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 685, in check_health
    if nativestr(self.read_response()) != 'PONG':
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 739, in read_response
    response = self._parser.read_response()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 340, in read_response
    raise error
redis.exceptions.ConnectionError: max number of clients reached

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 685, in check_health
    if nativestr(self.read_response()) != 'PONG':
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 739, in read_response
    response = self._parser.read_response()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 340, in read_response
    raise error
redis.exceptions.ConnectionError: max number of clients reached

Then this infinity loop terminates with RecursionError

  File "/.venv/lib/python3.8/site-packages/redis/client.py", line 1606, in get
    return self.execute_command('GET', name)
  File "/.venv/lib/python3.8/site-packages/redis/client.py", line 898, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 1192, in get_connection
    connection.connect()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 567, in connect
    self.on_connect()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 663, in on_connect
    self.send_command('SELECT', self.db)
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 725, in send_command
    self.send_packed_command(self.pack_command(*args),
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 701, in send_packed_command
    self.check_health()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 690, in check_health
    self.send_command('PING', check_health=False)
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 725, in send_command
    self.send_packed_command(self.pack_command(*args),
  # --------------------------------- repeated hundreds of times ---------------------------------
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 698, in send_packed_command
    self.connect()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 567, in connect
    self.on_connect()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 663, in on_connect
    self.send_command('SELECT', self.db)
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 725, in send_command
    self.send_packed_command(self.pack_command(*args),
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 701, in send_packed_command
    self.check_health()
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 684, in check_health
    self.send_command('PING', check_health=False)
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 725, in send_command
    self.send_packed_command(self.pack_command(*args),
  File "/.venv/lib/python3.8/site-packages/redis/connection.py", line 706, in send_packed_command
    sendall(self._sock, item)
  File "/.venv/lib/python3.8/site-packages/redis/_compat.py", line 9, in sendall
    return sock.sendall(*args, **kwargs)
  File "/.venv/lib/python3.8/site-packages/gevent/_socketcommon.py", line 699, in sendall
    return _sendall(self, data_memory, flags)
  File "/.venv/lib/python3.8/site-packages/gevent/_socketcommon.py", line 389, in _sendall
    len_data_memory = len(data_memory)
RecursionError: maximum recursion depth exceeded while calling a Python object

Is there a limit on the number of retries, or it's apparently a bug in exception handling?

Thanks in advance

@zhuang42 zhuang42 changed the title Infinity retry on max number of clients reached exceptions Infinity retry on the exception of max number of clients reached Jan 24, 2023
@dvora-h
Copy link
Collaborator

dvora-h commented Jan 29, 2023

@zhuang42 Thanks for reporting this! Can you please check if the error occurred in newer versions of redis-py? we are only supports 4.x versions

@zhuang42
Copy link
Author

zhuang42 commented Feb 2, 2023

@dvora-h Thanks! This doesn't occur in 4.x versions

@zhuang42 zhuang42 closed this as completed Feb 2, 2023
@rad-pat
Copy link

rad-pat commented Jul 28, 2023

I just came across this issue with version 4.6.0.
I will see if I can generate a replica.

@rad-pat
Copy link

rad-pat commented Jul 28, 2023

Mine is a very similar issue, but seems to be for Sentinel only. Created a new issue here #2866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants