-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
calling thread.stop() can cause AttributeError #833
Comments
It's another incarnation of #732. There's a PR that fixes it, but hasn't been merged yet. |
I have implemented the fix on my clients, and it seems to work quiet well on the linux clients. However, it can still happen on the windows clients: redis_test\redis_handler.py:29: in exit |
Interesting. I don't have a Windows client to test with, but if you come up with a fix, I'm happy to merge it into my PR for #732 (assuming it still hasn't been merged). |
I have a minimal example code working on a windows client right now. RedisTest.py:
SyncServer.py:
This seems to replicate the error pretty consistent on my windows client (windows server 2008). After adding some logging, it seems like the main thread and the subscriber thread is have a race condition on the connection.
It seem like the WorkerThread is closing the connection while send_packed_command is using it. To avoid this, I tried to add a mutex protecting on disconnect and send_packed_command in connection.py. I will keep you updated, if I find a more permanent solution |
Ok, it seems like i found the cause of the second issue.
And here is what happens: The logs to back it up:
The proposed fix for this would be to improve the stop() method of the thread, only unsubscribing channels/patterns, if there are any.
|
Actually the latter seems to be the key issue. I have now removed the mutex from connection.py and only implemented the fix in stop(). I have implemented this fix on my four windows clients, just to give it some exercise. Btw. I replicated the error on my windows server 2008 clients, however on my windows 10 pc, I haven't had any success with reproducing the error. @rolette I committed the fix on my fork, happy to hear your thoughts on it. |
Quick update:
This is actually an error I saw earlier and made a small quick-and-dirty fix for it, to debug the other issue (I was pretty sure it was because I stressed the redis server) The fix was just to check that the response received was not a long:
It seems like the redis server did send an integer reply back and it is unexpected. Anyway I don't believe the code should crash because of that. I might look in to it, if I get some time. |
I saw your update earlier this morning and realized that this is not the same issue as #732, but it follows the same pattern. Most of the stack trace is the same, but it's coming from a different path. I've never used the pub/sub bits in redis-py, but based on your log messages, it appears that two different threads are trying to use the same connection. If the main thread is trying to reset the connection while the worker thread is still in its polling loop, you'll run into the same sort of issues I fixed on the connection pool in my PR for #732. The change you checked in to have stop() skip over unsubscribing will help in some cases, but the underlying problem is still there for anyone that has active subscriptions. |
Yeah you are right, it is not the same issue as #732, I saw that when I started to dig in to it. The thing is that the way the workerthread is stopped, is by removing any active subscriptions, causing it to exit the loop. But I actually don't skip unsubscribing. I check if any active subscriptions are available in either channels or patterns and unsubscribe it accordingly. |
This issue was fixed in version 3.2.0. |
I am using the publish/subscribe part of redis and using the builtin thread to receive events.
However, sometimes it will fail when calling stop()
I am using a 'with' statement to start and stop the thread, as shown below:
In the 'with' statement i will normally wait for an specific event, but sometimes it will fail when exiting the 'with' statement
The traceback when this happens are:
it seems like _sock is getting deleted while the send_packed_command is running
The text was updated successfully, but these errors were encountered: