[PATCH 2 of 9 cubicweb] [server] avoid a possible race condition on _CnxSetPool.close()

Philippe Pepiot ph at itsalwaysdns.eu
Tue Mar 31 18:28:57 CEST 2020


# HG changeset patch
# User Philippe Pepiot <ph at itsalwaysdns.eu>
# Date 1585574363 -7200
#      Mon Mar 30 15:19:23 2020 +0200
# Node ID ef81cde04bf23382c0eee054a75ca815cb308aa6
# Parent  871eaf34586733ab684e675c4b5edfa47a03253f
# Available At https://philpep.org/pub/hg/cubicweb
#              hg pull https://philpep.org/pub/hg/cubicweb -r ef81cde04bf2
[server] avoid a possible race condition on _CnxSetPool.close()

The pool could become empty between time to check and time to use.

diff --git a/cubicweb/server/repository.py b/cubicweb/server/repository.py
--- a/cubicweb/server/repository.py
+++ b/cubicweb/server/repository.py
@@ -198,9 +198,11 @@ class _CnxSetPool(_BaseCnxSet):
             yield cnxset
 
     def close(self):
-        while not self._queue.empty():
-            cnxset = self._queue.get_nowait()
-
+        while True:
+            try:
+                cnxset = self._queue.get_nowait()
+            except queue.Empty:
+                break
             try:
                 cnxset.close(True)
             except Exception as e:



More information about the cubicweb-devel mailing list