[CalendarServer-changes] [13806] twext/trunk/twext/enterprise/adbapi2.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 31 11:35:53 PDT 2014


Revision: 13806
          http://trac.calendarserver.org//changeset/13806
Author:   cdaboo at apple.com
Date:     2014-07-31 11:35:53 -0700 (Thu, 31 Jul 2014)
Log Message:
-----------
Fix thread related race condition that could cause unit tests to hang.

Modified Paths:
--------------
    twext/trunk/twext/enterprise/adbapi2.py

Modified: twext/trunk/twext/enterprise/adbapi2.py
===================================================================
--- twext/trunk/twext/enterprise/adbapi2.py	2014-07-31 02:38:58 UTC (rev 13805)
+++ twext/trunk/twext/enterprise/adbapi2.py	2014-07-31 18:35:53 UTC (rev 13806)
@@ -1041,17 +1041,19 @@
             waiting = self._waiting[0]
             waiting._stopWaiting()
 
-        # Phase 2: Wait for all the Deferreds from the L{_ConnectedTxn}s that
-        # have *already* been stopped.
-        while self._finishing:
-            yield _fork(self._finishing[0][1])
-
-        # Phase 3: All of the busy transactions must be terminated first.  As each
+        # Phase 2: All of the busy transactions must be terminated first.  As each
         # one is terminated, it will remove itself from the list. Note we terminate
         # and not abort the transaction to ensure they cannot be re-used.
         while self._busy:
             yield self._busy[0].terminate()
 
+        # Phase 3: Wait for all the Deferreds from the L{_ConnectedTxn}s that
+        # have *already* been stopped. Note we do this AFTER clearing out
+        # self._busy, to make sure any that were busy have properly finished
+        # (been added to self._free) before we clear out the free ones.
+        while self._finishing:
+            yield _fork(self._finishing[0][1])
+
         # Phase 4: All transactions should now be in the free list, since
         # "abort()" will have put them there.  Shut down all the associated
         # ThreadHolders.
@@ -1183,7 +1185,11 @@
             self._busy.append(txn)
             waiting._unspoolOnto(txn)
         else:
-            self._free.append(txn)
+            # If we are stopping, never add to the free list - release it
+            if self._stopping:
+                txn._releaseConnection()
+            else:
+                self._free.append(txn)
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140731/61236ead/attachment.html>


More information about the calendarserver-changes mailing list