Paolo ponzano - 271 - May 12, 2014r

Hello, I’ve got a problem with ServiceStack/Redis and my AuthProvider…sometime not always I get this kind of exception "
unknown command ‘urn:iauthsession:SYNrA8QHA5Mi86xscJu8’, sPort: 63928, LastCommand:
"

and here’s the Stack Trace

   at ServiceStack.Redis.RedisNativeClient.CreateResponseError(String error)
   at ServiceStack.Redis.RedisNativeClient.ParseSingleLine(String r)
   at ServiceStack.Redis.RedisClient.<>c__DisplayClass161.&lt;Get&gt;b__15(RedisClient r)<br>&nbsp;&nbsp; at ServiceStack.Redis.RedisClient.Exec[T](Func2 action)
   at ServiceStack.ServiceExtensions.GetSession(IRequest httpReq, Boolean reload)
   at ServiceStack.AuthenticateAttribute.Execute(IRequest req, IResponse res, Object requestDto)
   at ServiceStack.RequestFilterAttribute.RequestFilter(IRequest req, IResponse res, Object requestDto)
   at ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)

My SS request is something as

 [Authenticate]
        public object Any(RicercaRapportoRequest request)
        {
            string storedProcedure = StoredProcedures.Get(“xxx”);

            var result = Db.ExecCommand(dbCmd =>
            {
                dbCmd.CommandText = storedProcedure;
                dbCmd.Parameters.Add(parameters…);

                return dbCmd.ExecuteReader().ConvertToList<RicercaRapportoItem>();
            });

            return result;
        }

What can go wrong here?
Thanks

You’re showing a Redis Exception with OrmLite source code? I wont be able to repro this. Do you have anywhere where you use the Redis client directly?

paolo ponzano:

No, I just use Redis client for keeping authentication’s session… so my keys are (for now)
urn:iauthsession:2hgTfXy8kRMUevYxRlBu
urn:iauthsession:ipps8qXb9eW8y4Oj32Js
urn:iauthsession:eNGVNbKpXAN9KRHbdVoL

it seems that for some reason it tries to execute that command “‘urn:iauthsession:SYNrA8QHA5Mi86xscJu8’,” instead of get urn:iauthsession:lXRuzZEb1eoHGGsju6RP

How is your Redis and AuthFeature registered?

paolo ponzano:

Here’s my Redis registration.

public void RegisterCacheProvider(Funq.Container container)
        {
            bool redisEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get(“enableRedis”));

            if (redisEnabled)
            {
                var strRedisHost = ConfigurationManager.AppSettings.Get(“redisHost”);

                var redisClient = new ServiceStack.Redis.RedisClient(strRedisHost);
             
                container.Register<ICacheClient>(redisClient);
            }
            else
            {
                var cacheClient = new MemoryCacheClient();
                container.Register<ICacheClient>(cacheClient);
            }

        }

and after I register my Auth as

    Plugins.Add(new IdeaAuthFeature(ConfigurationManager.ConnectionStrings[“default”].ConnectionString, sessionExpiry));

My IdeaAuthFeature’s registration is

     public void Register(IAppHost appHost)
        {
            var container = appHost.GetContainer();

            if (container.TryResolve<IUserAuthRepository>() == null)
                container.Register<IUserAuthRepository>(new InMemoryAuthRepository());  

            if (container.TryResolve<ICacheClient>() == null)
                container.Register<ICacheClient>(new MemoryCacheClient());              // Cache provider to store sessions.

            var authFeature = new AuthFeature(
                () => new IdeaAuthUserSession(),
                new IAuthProvider[]
                {
                    new IdeaAuthProvider()
                    {
                        Provider = ProviderName,
                        ConnectionString = connectionString,
                        SessionExpiry = sessionExpiry // Expire assoluta riferita al momento di creazione della sessione.
                    }
                }
            );

            appHost.Plugins.Add(authFeature);
            authFeature.Register(appHost);
        }

The strange thing is that this only happens sometimes…maybe I  got 3 errors, the 4 is ok…

paolo ponzano:

Right now I got 2 new exception

Protocol error: expected ‘$’, got ‘*’, sPort: 64460, LastCommand:

   at ServiceStack.Redis.RedisNativeClient.CreateResponseError(String error)
   at ServiceStack.Redis.RedisNativeClient.ParseSingleLine(String r)
   at ServiceStack.Redis.RedisClient.<>c__DisplayClass161.&lt;Get&gt;b__15(RedisClient r)<br>&nbsp;&nbsp; at ServiceStack.Redis.RedisClient.Exec[T](Func2 action)
   at ServiceStack.ServiceExtensions.GetSession(IRequest httpReq, Boolean reload)
   at ServiceStack.AuthenticateAttribute.Execute(IRequest req, IResponse res, Object requestDto)
   at ServiceStack.RequestFilterAttribute.RequestFilter(IRequest req, IResponse res, Object requestDto)
   at ServiceStack.Host.ServiceRunner1.Execute(IRequest request, Object instance, TRequest requestDto)<br><br>Object reference not set to an instance of an object.<br><br>&nbsp;&nbsp; at ServiceStack.Redis.RedisNativeClient.HandleSocketException(SocketException ex)<br>&nbsp;&nbsp; at ServiceStack.Redis.RedisNativeClient.FlushSendBuffer()<br>&nbsp;&nbsp; at ServiceStack.Redis.RedisNativeClient.SendExpectData(Byte[][] cmdWithBinaryArgs)<br>&nbsp;&nbsp; at ServiceStack.Redis.RedisClient.&lt;&gt;c__DisplayClass161.<Get>b__15(RedisClient r)
   at ServiceStack.Redis.RedisClient.Exec[T](Func2 action)<br>&nbsp;&nbsp; at ServiceStack.ServiceExtensions.GetSession(IRequest httpReq, Boolean reload)<br>&nbsp;&nbsp; at ServiceStack.AuthenticateAttribute.Execute(IRequest req, IResponse res, Object requestDto)<br>&nbsp;&nbsp; at ServiceStack.RequestFilterAttribute.RequestFilter(IRequest req, IResponse res, Object requestDto)<br>&nbsp;&nbsp; at ServiceStack.Host.ServiceRunner1.Execute(IRequest request, Object instance, TRequest requestDto)

You’re using an instance of redisClient as a singleton instance. The RedisClient isn’t thread-safe only the ClientManagers are. See how to register a Redis CacheClient here:
https://github.com/ServiceStack/ServiceStack/wiki/Caching#redis

paolo ponzano:

Hello Demis,
It seems to work! Thanks!