Browse Source

Merge pull request #7117 from richardkchapman/redis_threadloop

HPCC-13232 Correct recursive threadchain creation

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 10 years ago
parent
commit
5b4358823b
1 changed files with 10 additions and 1 deletions
  1. 10 1
      plugins/redis/redis.cpp

+ 10 - 1
plugins/redis/redis.cpp

@@ -43,6 +43,7 @@ class Connection;
 static const char * REDIS_LOCK_PREFIX = "redis_ecl_lock";
 static const char * REDIS_LOCK_PREFIX = "redis_ecl_lock";
 static __thread Connection * cachedConnection;
 static __thread Connection * cachedConnection;
 static __thread ThreadTermFunc threadHookChain;
 static __thread ThreadTermFunc threadHookChain;
+static __thread bool threadHooked;
 
 
 static void * allocateAndCopy(const void * src, size_t size)
 static void * allocateAndCopy(const void * src, size_t size)
 {
 {
@@ -158,7 +159,10 @@ public :
     ~MainThreadCachedConnection()
     ~MainThreadCachedConnection()
     {
     {
         if (cachedConnection)
         if (cachedConnection)
+        {
             cachedConnection->Release();
             cachedConnection->Release();
+            cachedConnection = NULL;
+        }
     }
     }
 } mainThread;
 } mainThread;
 
 
@@ -174,6 +178,7 @@ static void releaseContext()
         (*threadHookChain)();
         (*threadHookChain)();
         threadHookChain = NULL;
         threadHookChain = NULL;
     }
     }
+    threadHooked = false;
 }
 }
 Connection::Connection(ICodeContext * ctx, const char * _options, unsigned __int64 _database, const char * password, unsigned __int64 _timeout)
 Connection::Connection(ICodeContext * ctx, const char * _options, unsigned __int64 _database, const char * password, unsigned __int64 _timeout)
   : database(0), timeout(_timeout), port(0), serverIpPortPasswordHash(hashServerIpPortPassword(ctx, _options, password))
   : database(0), timeout(_timeout), port(0), serverIpPortPasswordHash(hashServerIpPortPassword(ctx, _options, password))
@@ -290,7 +295,11 @@ Connection * Connection::createConnection(ICodeContext * ctx, const char * optio
     if (!cachedConnection)
     if (!cachedConnection)
     {
     {
         cachedConnection = new Connection(ctx, options, _database, password, _timeout);
         cachedConnection = new Connection(ctx, options, _database, password, _timeout);
-        threadHookChain = addThreadTermFunc(releaseContext);
+        if (!threadHooked)
+        {
+            threadHookChain = addThreadTermFunc(releaseContext);
+            threadHooked = true;
+        }
         return LINK(cachedConnection);
         return LINK(cachedConnection);
     }
     }