Explorar o código

[desktop] Fix another deadlock fetching thrift clients

Wait until the queue has been filled with connections before adding
it to the pool. This is done last because any exceptions thrown
by the client construction could result in there being no
connections available in this pool. When `get_client` is called next,
it would skip this block because the key has a value, but then it
would deadlock later because there are no connections for it to
fetch from the pool.
Erick Tryzelaar %!s(int64=10) %!d(string=hai) anos
pai
achega
26d954504a
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  1. 9 1
      desktop/core/src/desktop/lib/thrift_util.py

+ 9 - 1
desktop/core/src/desktop/lib/thrift_util.py

@@ -184,11 +184,19 @@ class ConnectionPooler(object):
       try:
       try:
         if _get_pool_key(conf) not in self.pooldict:
         if _get_pool_key(conf) not in self.pooldict:
           q = LifoQueue(self.poolsize)
           q = LifoQueue(self.poolsize)
-          self.pooldict[_get_pool_key(conf)] = q
           for i in xrange(self.poolsize):
           for i in xrange(self.poolsize):
             client = construct_superclient(conf)
             client = construct_superclient(conf)
             client.CID = i
             client.CID = i
             q.put(client, False)
             q.put(client, False)
+
+          # Wait until the queue has been filled with connections before adding
+          # it to the pool. This is done last because any exceptions thrown
+          # by the client construction could result in there being no
+          # connections available in this pool. When `get_client` is called next,
+          # it would skip this block because the key has a value, but then it
+          # would deadlock later because there are no connections for it to
+          # fetch from the pool.
+          self.pooldict[_get_pool_key(conf)] = q
       finally:
       finally:
         self.dictlock.release()
         self.dictlock.release()