Reputation: 1150
I'm using the servicestack.redis
client to connect. Redis is basically being used as SignalR backplane (which uses the booksleeve client). I'm additionally using ServiceStack.Redis client to maintain a connection list
I have code like this in the RedisConnectionManager.cs
(along with similar methods for AddConnection
and GetConnections
. The AddConnection
and RemoveConnection
are called by methods on the SignalR hub.
Now let's get into the issue... Once in a while, I get a InvalidOperationException
with the message A transaction is already in progress
in the CreateTransaction
call. This is generally after an exception is thrown by Redis in the if statement if (connections == null || connections.Count == 0)
.
Anyway, what happens is that after that, things no longer work until I restart the process - since everytime I get an InvalidOperationException
. I poked into the ServiceStack.Redis client code and according to the docs, it should either commit or discard the transaction. Seems like that's not happening and then the client is in a limbo state since the RedisClient.Transaction
object is never null
ed.
I couldn't find a bug tracker for ServiceStack.Redis
so hopefully folks on SO will know better.
public void RemoveConnection(string clientId, string connectionId)
{
try
{
var key = "CONNECTION_" + clientId;
redis.Watch(key);
var connections = redisTypedClient.Lists[key];
if (connections == null || connections.Count == 0)
{
return;
}
using (var t = redisTypedClient.CreateTransaction())
{
t.QueueCommand(c => c.RemoveItemFromList(connections, connectionId));
t.Commit();
}
}
finally
{
redis.UnWatch();
}
}
Upvotes: 1
Views: 578
Reputation: 1150
So the issue in this case was that I was reusing the redis connection which wasn't a good idea. As soon as I moved to creating and using a new Redis connection each time, this issue went away.
Upvotes: 1