I have a ServiceStack.Redis multi-threading collision. I have a kind of non-standard usage case for ServiceStack where I capture all routes in one "FallbackRoute". This means there is one service for that one route. Here is the DTO:
[FallbackRoute("/{Path*}")]
public class S3Request : IRequiresRequestStream{
public string Path{ get; set; }
public Stream RequestStream { get; set; }
}
The Service is:
public class S3Service : Service
{
public RedisUsersCredentials RedisUsersCredentials { get; set; }
// S3 Request Mutual Exclusion Objects:
static readonly object syncBucket = new object();
static readonly object syncObject = new object();
public object Get(S3Request request){
IRedisClient Redis = RedisUsersCredentials.RedisClient;
// Do a bunch of stuff with Redis
}
public object Put(S3Request request){
IRedisClient Redis = RedisUsersCredentials.RedisClient;
// Do a bunch of stuff with Redis
}
Then in AppHost.cs in the Configure block I have autowired redis:
container.Register<ServiceStack.Redis.IRedisClientsManager>(c =>
new ServiceStack.Redis.BasicRedisClientManager("localhost:6379"));
container.RegisterAutoWired<RedisUsersCredentials>();
I got this from posts on how to properly use the BasicRedisClientManager with multi-threading. But I get exceptions like:
multi-request: 581, sPort: 40900, LastCommand: SMEMBERS TenantOwnerSet:s3devel</Message><StackTrace>[S3Request: 4/1/2015 6:36:50 PM]:
[REQUEST: {}]
ServiceStack.Redis.RedisResponseException: Unknown reply on multi-request: 581, sPort: 40900, LastCommand: SMEMBERS TenantOwnerSet:s3devel
at ServiceStack.Redis.RedisNativeClient.CreateResponseError (string) <IL 0x0003a, 0x00153>
at ServiceStack.Redis.RedisNativeClient.ReadMultiData () <IL 0x000e5, 0x0060f>
at ServiceStack.Redis.RedisNativeClient.SendExpectMultiData (byte[][]) <IL 0x00037, 0x001db>
at ServiceStack.Redis.RedisNativeClient.SMembers (string) <IL 0x0001a, 0x000cf>
at ServiceStack.Redis.Generic.RedisTypedClient`1<string>.GetAllItemsFromSet (ServiceStack.Redis.Generic.IRedisSet`1<string>) <0x00083>
at ServiceStack.Redis.Generic.RedisClientSet`1<string>.GetAll () <0x0006f>
at S3OL.TenantManager.getTenantOwner () [0x0001e] in /home/admin/devgit/ols3/mono/src/TenantManager.cs:87
at S3OL.TenantManager..ctor (ServiceStack.Redis.IRedisClient,string) [0x00084] in /home/admin/devgit/ols3/mono/src/TenantManager.cs:60
at S3OL.BucketManager..ctor (ServiceStack.Redis.IRedisClient,string,string) [0x00016] in /home/admin/devgit/ols3/mono/src/BucketManager.cs:120
at S3OL.S3Service.Delete (S3OL.S3Request) [0x00195] in /home/admin/devgit/ols3/mono/Interface.cs:570
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,object,object) <IL 0x0000c, 0x000a3>
at ServiceStack.Host.ServiceRunner`1<S3OL.S3Request>.Execute (ServiceStack.Web.IRequest,object,S3OL.S3Request) <0x00642>
</StackTrace><Errors /></ResponseStatus></ErrorResponse>
Only happens when I have more than one client. I can hit it repeatedly with one client, and very fast. If I add a client at the same time it dies in one of these Redis exceptions.