[server] avoid a possible race condition on _CnxSetPool.close() draft
authorPhilippe Pepiot <ph@itsalwaysdns.eu>
Mon, 30 Mar 2020 15:19:23 +0200
changeset 12959 39ee325e6758
parent 12958 3667f6df1ec3
child 12960 2c3a8a4f5a02
[server] avoid a possible race condition on _CnxSetPool.close() The pool could become empty between time to check and time to use.
cubicweb/server/repository.py
--- a/cubicweb/server/repository.py	Mon Mar 30 15:17:10 2020 +0200
+++ b/cubicweb/server/repository.py	Mon Mar 30 15:19:23 2020 +0200
@@ -198,9 +198,11 @@
             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: