redis-py: Race condition in connection disconnect
It seems like there is a race condition in the code for Connection.disconnect(). I run redis as a celery broker, so I seem to be running into a situation where I get a TypeError: NoneType has no attribute _close(). It would appear that in one process disconnect() is being called and setting the self._sock to None while another process has already executed the if statement that checks if self._sock is None.
def disconnect(self):
"Disconnects from the Redis server"
self._parser.on_disconnect()
if self._sock is None:
return
try:
self._sock.shutdown(socket.SHUT_RDWR)
self._sock.close()
except socket.error:
pass
self._sock = None
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 32 (15 by maintainers)
Commits related to this issue
- Disconnect clients from pool safely This PR tries to solve the issues raised by #732 regarding the danger of disconnect clients from the `ConnectionPool.disconnect` method executed by a Thread differ... — committed to pfreixes/redis-py by pfreixes 8 years ago
- POC fix for #732 — committed to pfreixes/redis-py by pfreixes 8 years ago
- fixes the various scenarios where ConnectionPool.disconnect() and Connection.disconnect() were ripping connections out from under the threads or processes that owned them https://github.com/andymccur... — committed to rolette/redis-py by rolette 8 years ago
- fixes the various scenarios where ConnectionPool.disconnect() and Connection.disconnect() were ripping connections out from under the threads or processes that owned them https://github.com/andymccur... — committed to discord/redis-py by rolette 8 years ago
- fixes the various scenarios where ConnectionPool.disconnect() and Connection.disconnect() were ripping connections out from under the threads or processes that owned them https://github.com/andymccur... — committed to exponea/redis-py by rolette 8 years ago
- Use thread-local for connecting to redis to avoid race conditions on master failover https://github.com/andymccurdy/redis-py/issues/732 APP-2467 APP-3994 — committed to exponea/flask-redis-sentinel by lalinsky 7 years ago
- fixes the various scenarios where ConnectionPool.disconnect() and Connection.disconnect() were ripping connections out from under the threads or processes that owned them https://github.com/andymccur... — committed to discord/redis-py by rolette 8 years ago
- fixes the various scenarios where ConnectionPool.disconnect() and Connection.disconnect() were ripping connections out from under the threads or processes that owned them https://github.com/andymccur... — committed to discord/redis-py by rolette 8 years ago
Ill be out two days. I will check it then. In any case thanks for your detailed comment.