server/repository.py
changeset 8954 9d30719142bf
parent 8947 3bbd416b09ec
parent 8953 041804bc48e9
child 9007 e27337dfec8c
--- a/server/repository.py	Mon Apr 29 11:22:21 2013 +0200
+++ b/server/repository.py	Mon Apr 29 11:43:36 2013 +0200
@@ -1637,8 +1637,22 @@
         # into the pyro name server
         if self._use_pyrons():
             self.looping_task(60*10, self._ensure_pyro_ns)
+        # install hacky function to free cnxset
+        self.looping_task(60, self._cleanup_pyro)
         return daemon
 
+    def _cleanup_pyro(self):
+        """Very hacky function to cleanup session left by dead Pyro thread.
+
+        There is no clean pyro callback to detect this.
+        """
+        for session in self._sessions.values():
+            for thread, cnxset in session._threads_in_transaction.copy():
+                if not thread.isAlive():
+                    self.warning('Freeing cnxset used by dead pyro threads: %',
+                                 thread)
+                    session._free_thread_cnxset(thread, cnxset)
+
     def _ensure_pyro_ns(self):
         if not self._use_pyrons():
             return