[server] add a looping task to free unused cnxsets capture by dead pyro stable cubicweb-centos-version-3.16.4-1 cubicweb-debian-version-3.16.4-1 cubicweb-version-3.16.4
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 16 Apr 2013 16:51:18 +0200
branchstable
changeset 8953 041804bc48e9
parent 8948 c360005220d7
child 8954 9d30719142bf
child 8958 e864c54bcf95
[server] add a looping task to free unused cnxsets capture by dead pyro When a pyro client disconnects, we're not necessarily notified so they can hang on to their session/cnxset forever. Don't let them do that. The hacky looping task is only installed when pyro is enabled. This optional activation save this very hacky patch from being rejected. closes #2825380
server/repository.py
--- a/server/repository.py	Fri Apr 26 18:21:18 2013 +0200
+++ b/server/repository.py	Tue Apr 16 16:51:18 2013 +0200
@@ -1635,8 +1635,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