Commit 84aa0c13 authored by Jason Madden's avatar Jason Madden

Correct potential deadlock in ClientStorage:tpc_begin by being sure to release...

Correct potential deadlock in ClientStorage:tpc_begin by being sure to release locks in a finally block.
parent 09db1b2e
...@@ -1111,19 +1111,20 @@ class ClientStorage(object): ...@@ -1111,19 +1111,20 @@ class ClientStorage(object):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
self._tpc_cond.acquire() self._tpc_cond.acquire()
self._midtxn_disconnect = 0 try:
while self._transaction is not None: self._midtxn_disconnect = 0
# It is allowable for a client to call two tpc_begins in a while self._transaction is not None:
# row with the same transaction, and the second of these # It is allowable for a client to call two tpc_begins in a
# must be ignored. # row with the same transaction, and the second of these
if self._transaction == txn: # must be ignored.
self._tpc_cond.release() if self._transaction == txn:
raise POSException.StorageTransactionError( raise POSException.StorageTransactionError(
"Duplicate tpc_begin calls for same transaction") "Duplicate tpc_begin calls for same transaction")
self._tpc_cond.wait(30) self._tpc_cond.wait(30)
self._transaction = txn self._transaction = txn
self._tpc_cond.release() finally:
self._tpc_cond.release()
try: try:
self._server.tpc_begin(id(txn), txn.user, txn.description, self._server.tpc_begin(id(txn), txn.user, txn.description,
...@@ -1143,9 +1144,11 @@ class ClientStorage(object): ...@@ -1143,9 +1144,11 @@ class ClientStorage(object):
# the right way to set self._transaction to None # the right way to set self._transaction to None
# calls notify() on _tpc_cond in case there are waiting threads # calls notify() on _tpc_cond in case there are waiting threads
self._tpc_cond.acquire() self._tpc_cond.acquire()
self._transaction = None try:
self._tpc_cond.notify() self._transaction = None
self._tpc_cond.release() self._tpc_cond.notify()
finally:
self._tpc_cond.release()
def lastTransaction(self): def lastTransaction(self):
return self._cache.getLastTid() return self._cache.getLastTid()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment