liubiao4123 / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 0 forks source link

PooledRedisClientManager exception Cannot add unknown client back to the pool exception #37

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In multithreaded environement, with multiple pools, my script throw
"Cannot add unknown client back to the pool exception" exception from 
DisposeClient.

it seems when client had exceptions, there is a call to DisposeConnection()
but when the client is disposed, DisposeClient is called.

ClientManager need to be set to null in DisposeClient ?

Original issue reported on code.google.com by jeanmari...@gmail.com on 3 Sep 2010 at 4:53

GoogleCodeExporter commented 8 years ago
I don't suppose there is anyway to write a script to replicate this bug is 
there?

In order to ensure this bug stays fixed it would be nice to have a test case 
that exhibits these bugs.

Original comment by demis.be...@gmail.com on 3 Sep 2010 at 6:13

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
you can run this with a redis server on local default port.
multiple connections with the pool, wait 10 secs, then shutdown !
thanks

using System;
using ServiceStack.Redis;
using System.Threading;

namespace Test
{
    class Program
    {
        public static void Stuff() {
            while(true) {
                try {
                    using(RedisClient rc = (RedisClient)pool.GetClient()) {
                        rc.Set<DateTime>("test",DateTime.Now);
                    }
                }
                catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
                Thread.Sleep(10);
            }
        }

        public static PooledRedisClientManager pool;
        public static void Main(string[] args)
        {
            pool = new PooledRedisClientManager();
            try {
                Thread[] ths = new Thread[100];
                for(int i=0;i<ths.Length;i++) {
                    ths[i]=new Thread(new ThreadStart(Stuff));
                    ths[i].Start();
                }
                Console.WriteLine("running, waiting 10secs..");
                Thread.Sleep(10000);
                using(RedisClient rc = (RedisClient)pool.GetClient()) {
                    Console.WriteLine("shutdown redis !");
                    rc.Shutdown();
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Original comment by jeanmari...@gmail.com on 4 Sep 2010 at 10:35

GoogleCodeExporter commented 8 years ago
Hi Thanks for this, I've got new builds attached that hopefully resolves this 
issue.

Let me know how it goes.

Cheers,
D

Original comment by demis.be...@gmail.com on 5 Sep 2010 at 12:40

Attachments:

GoogleCodeExporter commented 8 years ago
Fixed ! thanks a lot !

Original comment by jeanmari...@gmail.com on 8 Sep 2010 at 11:37

GoogleCodeExporter commented 8 years ago
Sweet good to know, closing.

Original comment by demis.be...@gmail.com on 8 Sep 2010 at 11:40