-
Notifications
You must be signed in to change notification settings - Fork 13
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
Improper isolation using async_transaction? #26
Comments
Yup, good spot, I think you're right. I haven't had much time to look into it yet, but I remember that the StackExchange.Redis client deals with this, and handles transactions in multiplexed connections. I haven't looked at the code yet, but might be worth seeing if they've got any useful approach to consider. Otherwise, where transactions are involved, either some form of mutex (to avoid interspersed WATCHes) or use of connection pooling would work here. The latter is probably the simplest approach at first glance. |
…nnections instead of a connection manager, in order to avoid issues related to interspersed WATCH commands on the same thread. See #26.
…nnections instead of a connection manager, in order to avoid issues related to interspersed WATCH commands on the same thread. See #26.
Fixed in 43cd03f. |
I've spent the last 2 days diving into the details of redis connections and how they relate to transactions. I've been trying to figure out what the right way to setup an async-web-server that talks to redis would be. So I've learned about the various connection strategies available to me (bb8, deadpool, and
MultiplexedConnection
s). While doing so I came across your comment, and after some testing have determined that this is only safe to use if theasync_transaction!
has exclusive ownership of the connection it's using.In this project, however, I'm pretty sure using a
ManagedConnection
like this:ocypod/src/bin/ocypod-server.rs
Lines 37 to 44 in d965c4a
And so connections cloned by
actix
like such:ocypod/src/bin/ocypod-server.rs
Line 54 in d965c4a
maybe the red herring:
ocypod/src/bin/ocypod-server.rs
Line 44 in d965c4a
ConnectionManager
doesn't actually perform any pooling, it just exposes aMultiplexedConnection
that re-connects automatically.I hope I'm wrong about all this and I don't understand some detail regarding the way these connections are managed (or some detail about actix for that matter, I'm using warp). But I'm pretty sure what's happening under the hood is the following:
If we were getting actual transaction isolation, you would expect the following code to infinite loop:
But it completes with a final value of 3, demonstrating a race condition.
If however the inner
async_transaction
gets it's own connection:Then this code infinite loops as expected.
So my current take-away, for the types of applications we're building, is that we need to use some sort of connection pooling, and perhaps we'd want to hook into
deadpool
spost-recycle
hook, in order to be sure that we're not watching some keys from a previous connection that returned it to the pool without un-watching all it's keys.I'd love to get your thoughts on the situation as the architecture of my application seems similar to yours.
The text was updated successfully, but these errors were encountered: