Skip to content

Commit

Permalink
[desktop] Fix another deadlock fetching thrift clients
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Erick Tryzelaar committed Jul 23, 2015
1 parent 3069684 commit 26d9545
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion desktop/core/src/desktop/lib/thrift_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,19 @@ def get_client(self, conf, get_client_timeout=None):
try:
if _get_pool_key(conf) not in self.pooldict:
q = LifoQueue(self.poolsize)
self.pooldict[_get_pool_key(conf)] = q
for i in xrange(self.poolsize):
client = construct_superclient(conf)
client.CID = i
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:
self.dictlock.release()

Expand Down

0 comments on commit 26d9545

Please sign in to comment.