Skip to content
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

Stderr backtrace caused by redis.client.Redis.__del__ on process exit. #3014

Open
byron-lambda opened this issue Oct 17, 2023 · 1 comment
Open

Comments

@byron-lambda
Copy link

byron-lambda commented Oct 17, 2023

Version: 5.0.1

Platform: Python 3.8.18 on Ubuntu 20.04

Description: Backtrace to stderr on process exit due to redis.client.Redis.__del__()

Here is the trace:

Exception ignored in: <function Redis.__del__ at 0x7fcf29e50ca0>
Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/redis/client.py", line 491, in __del__
  File "/venv/lib/python3.8/site-packages/redis/client.py", line 506, in close
  File "/venv/lib/python3.8/site-packages/redis/connection.py", line 1155, in disconnect
  File "/venv/lib/python3.8/site-packages/redis/connection.py", line 1062, in _checkpid
AttributeError: 'NoneType' object has no attribute 'getpid'

Occurs due to unloaded globals being referenced in methods called in destructors on process exit. See warning in Python docs here

This can be fixed in a couple of ways:

  1. Add an exception handler to redis.client.Redis.__del__() as it appears has been done in many other destructors (
    def __del__(self):
    for example)
  2. Add references to required globals to the redis.connection.ConnectionPool class and call via the references. The globals that require references in are os.getpid and chain (from itertools) afaict.

NOTE: It is quite hard to come up with a small piece of code to reproduce this issue as it is caused by a race in the unload order at exit. I'll try to come up with something reliable if req'd.

NOTE: The issue is triggered by

self.connection_pool.disconnect()
which was recently introduced in 012f7cf

@diogosilva30
Copy link

Can confirm this behaviour with version 5.0.1 with Django. I get this error when the development server restarts

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

No branches or pull requests

2 participants