backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 16 Jul 2010 12:40:22 +0200
changeset 5982 30985571dbc9
parent 5981 3472c051da77 (current diff)
parent 5976 00b1b6b906cf (diff)
child 5983 e51796b9caf3
backport stable
server/sources/native.py
--- a/server/pool.py	Fri Jul 16 11:41:17 2010 +0200
+++ b/server/pool.py	Fri Jul 16 12:40:22 2010 +0200
@@ -67,6 +67,9 @@
                 cnx.rollback()
             except:
                 source.critical('rollback error', exc_info=sys.exc_info())
+                # error on rollback, the connection is much probably in a really
+                # bad state. Replace it by a new one.
+                self.reconnect(source)
 
     def close(self, i_know_what_i_do=False):
         """close all connections in the pool"""
--- a/server/sources/native.py	Fri Jul 16 11:41:17 2010 +0200
+++ b/server/sources/native.py	Fri Jul 16 12:40:22 2010 +0200
@@ -468,13 +468,17 @@
         try:
             cursor = self.doexec(session, sql, args)
         except (self.OperationalError, self.InterfaceError):
+            if session.mode == 'write':
+                # do not attempt to reconnect if there has been some write
+                # during the transaction
+                raise
             # FIXME: better detection of deconnection pb
             self.warning("trying to reconnect")
             session.pool.reconnect(self)
             cursor = self.doexec(session, sql, args)
         except (self.DbapiError,), exc:
             # We get this one with pyodbc and SQL Server when connection was reset
-            if exc.args[0] == '08S01':
+            if exc.args[0] == '08S01' and session.mode != 'write':
                 self.warning("trying to reconnect")
                 session.pool.reconnect(self)
                 cursor = self.doexec(session, sql, args)