Skip to content

Race condition in connection disconnect #1148

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
viktorvorobev opened this issue Mar 12, 2019 · 4 comments
Closed

Race condition in connection disconnect #1148

viktorvorobev opened this issue Mar 12, 2019 · 4 comments
Labels

Comments

@viktorvorobev
Copy link

viktorvorobev commented Mar 12, 2019

Excuse me, but it looks like this issue: #732 still occurs in some situations, and unfortunately, I can not actually tell why.
I'm facing this when I'm trying to test out my code using pytest and Travis, current versions of everything are:
redis-py: 3.2.0, redis: 4.0.9
Platform: python: 2.7.14, Ubuntu 14.04
Stack trace:

../../../virtualenv/python2.7.14/lib/python2.7/site-packages/redis/client.py:2968: in close
    self.reset()
../../../virtualenv/python2.7.14/lib/python2.7/site-packages/redis/client.py:2958: in reset
    self.connection.disconnect()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = Connection<host=localhost,port=6379,db=0>
    def disconnect(self):
        "Disconnects from the Redis server"
        self._parser.on_disconnect()
        if self._sock is None:
            return
        try:
            if os.getpid() == self.pid:
                self._sock.shutdown(socket.SHUT_RDWR)
>           self._sock.close()
E           AttributeError: 'NoneType' object has no attribute 'close'

../../../virtualenv/python2.7.14/lib/python2.7/site-packages/redis/connection.py:587: AttributeError
------------------------------ Captured log call -------------------------------
server.py                  106 WARNING  'NoneType' object has no attribute 'readline'

P.S.: If this will help, it looks like with version 2.10.6 everything works smoothly.

@andymccurdy
Copy link
Contributor

@victorvorobev Did you ever figure out what was going on here? Are you trying to share a Connection across multiple threads? Connections are not meant to be thread safe.

@viktorvorobev
Copy link
Author

@andymccurdy
Unfortunately, I'm still not quite sure, but it looks like that pytest is the one that should be blamed. My tests were written a bit incorrect and those connect and disconnect methods were called as setup and teardown methods for every test. After I changed that fact everything became more stable.

I don't know though why everything worked fine with version 2.10.6.

@github-actions
Copy link
Contributor

This issue is marked stale. It will be closed in 7 days if it is not updated.

@github-actions github-actions bot added the Stale label Jun 29, 2020
@andymccurdy
Copy link
Contributor

This should have been resolved in redis-py 3.4.0. If you're still having issues, feel free to re-open this.

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

No branches or pull requests

2 participants