Open cosminacho opened 1 year ago
See https://github.com/redis/redis-py/pull/2666#issuecomment-1514452720 for the explanation why this happens. PR https://github.com/redis/redis-py/pull/2719 would potentially fix this.
@agronholm I don't think #2719 will fix it because it fixes the sync connection and this issue is in the async connection (maybe #2695 will fix it).
@cosminacho Can you confirm that the issue solved in #2695?
I am still seeing this issue in 5.02
Version: 4.5.4
Platform: Windows / Linux - Python 3.10.10
Description: When cancelling a pubsub task that is listening for messages, the ConnectionError exception is thrown. This seems like an internal library problem because I can't catch the exception inside redis_subscribe function and the exception is thrown only after the CancellationError is raised inside the task.
Is this the intended behaviour? If so, what is an elegant work-around?
This code used to work in the previous versions of redis (4.5.3 an below).
redis_client is a global variable, initialized on the startup event of a server. The redis_subscribe function is supposed to be called inside endpoints that feed messages using websockets or server sent events. So the cancellation of the task needs to happen when for example a client disconnects from the server.