[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 31 Mar 2010 12:53:24 +0200
branchstable
changeset 5108 8495d580a580
parent 5107 3694bd379513
child 5109 5cf83b9356d5
child 5110 e1f0fb044d94
[session] try to reconnect on unexpected error in system_sql. We need this for proper reconnection of pool used by hooks or looping task doing sql queries (such as cw_cleanup_transaction)
server/session.py
--- a/server/session.py	Wed Mar 31 12:51:35 2010 +0200
+++ b/server/session.py	Wed Mar 31 12:53:24 2010 +0200
@@ -278,8 +278,13 @@
         """return a sql cursor on the system database"""
         if not sql.split(None, 1)[0].upper() == 'SELECT':
             self.mode = 'write'
-        return self.pool.source('system').doexec(self, sql, args,
-                                                 rollback=rollback_on_failure)
+        source = self.pool.source('system')
+        try:
+            return source.doexec(self, sql, args, rollback=rollback_on_failure)
+        except (source.OperationalError, source.InterfaceError):
+            source.warning("trying to reconnect")
+            self.pool.reconnect(self)
+            return source.doexec(self, sql, args, rollback=rollback_on_failure)
 
     def set_language(self, language):
         """i18n configuration for translation"""