Skip to content

With blocking xread, redis connection can be released while still waiting for response #2663

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
swilson11 opened this issue Mar 24, 2023 · 1 comment
Labels

Comments

@swilson11
Copy link

Version: redis-py = 4.5.3 redis = 7.0.5

Platform: Python 3.9 on Mac Ventura (M1 hardware)

Description:
I have a websocket server. Clients connect and request data for different redis streams. The main event loop for the websocket does a blocking xread command on the requested stream (block=0), and when data is available it sends it out through the websocket.

If the websocket client disconnects, there is no way to interrupt the blocking xread command on the server side, and the event loop task is just killed off.

This results in the finally clause of the redis client execute_command method being invoked, which releases the connection back into the connection pool. At this point though, the connection itself is stuck on a blocking read from redis, waiting for a response to the xread command.

At some point in the future, the connection is then given out from the pool to a new client, but the connection is still stuck on the blocking read, and won't do anything until a message arrives in the stream, causing some odd behavior in the new client that is trying to use the connection.

Would it be possible to detect if a connection is stuck like this when releasing it back into the pool, and clean it up if so?

In the mean time I can use a polled approach to reading from the stream, but any advice on how to implement this with a blocking read would be appreciated.

Copy link
Contributor

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

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

1 participant