[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
--- 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