← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/launchpad/oneiric-librarian-bug-871596 into lp:launchpad

 

Gavin Panella has proposed merging lp:~allenap/launchpad/oneiric-librarian-bug-871596 into lp:launchpad.

Requested reviews:
  Stuart Bishop (stub)
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/launchpad/oneiric-librarian-bug-871596/+merge/79175

It seems that disconnection errors behave slightly differently on Oneiric... possibly. This branch intercepts pgcode 57P01 - admin_shutdown - and allows transactions to be retried instead of just breaking at the first opportunity. Doing this lets the example test command given in the bug to complete without failure.
-- 
https://code.launchpad.net/~allenap/launchpad/oneiric-librarian-bug-871596/+merge/79175
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/launchpad/oneiric-librarian-bug-871596 into lp:launchpad.
=== modified file 'lib/lp/services/database/__init__.py'
--- lib/lp/services/database/__init__.py	2010-09-24 15:21:05 +0000
+++ lib/lp/services/database/__init__.py	2011-10-12 20:06:13 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """The lp.services.database package."""
@@ -9,14 +9,16 @@
     'write_transaction',
     ]
 
+from psycopg2 import OperationalError
 from psycopg2.extensions import TransactionRollbackError
-from storm.exceptions import DisconnectionError, IntegrityError
+from storm.exceptions import (
+    DisconnectionError,
+    IntegrityError,
+    )
 import transaction
 from twisted.python.util import mergeFunctionMetadata
 
-from canonical.database.sqlbase import (
-    reset_store,
-    )
+from canonical.database.sqlbase import reset_store
 
 
 RETRY_ATTEMPTS = 3
@@ -35,9 +37,18 @@
             try:
                 return func(*args, **kwargs)
             except (DisconnectionError, IntegrityError,
-                    TransactionRollbackError), exc:
+                    TransactionRollbackError):
                 if attempt >= RETRY_ATTEMPTS:
-                    raise # tried too many times
+                    raise  # tried too many times
+            except OperationalError, error:
+                # 57P01 is admin_shutdown:
+                #   FATAL: terminating connection due to administrator command
+                #   SSL connection has been closed unexpectedly
+                if error.pgcode == "57P01":
+                    if attempt >= RETRY_ATTEMPTS:
+                        raise  # tried too many times
+                else:
+                    raise
     return mergeFunctionMetadata(func, retry_transaction_decorator)
 
 
@@ -77,4 +88,3 @@
         return ret
     return retry_transaction(mergeFunctionMetadata(
         func, write_transaction_decorator))
-


Follow ups