]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- A revisit to this issue first patched in 0.9.5, apparently
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 Sep 2014 21:33:53 +0000 (17:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 Sep 2014 21:33:53 +0000 (17:33 -0400)
psycopg2's ``.closed`` accessor is not as reliable as we assumed,
so we have added an explicit check for the exception messages
"SSL SYSCALL error: Bad file descriptor" and
"SSL SYSCALL error: EOF detected" when detecting an
is-disconnect scenario.   We will continue to consult psycopg2's
connection.closed as a first check.
fixes #3021

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/dialects/postgresql/psycopg2.py

index 7c75996a4bff47ee5ddac38d7646adb7633c72d7..e5d6703e3a9c905f124031495587d44a60c0fec2 100644 (file)
 .. changelog::
     :version: 0.9.8
 
+    .. change::
+        :tags: bug, postgresql
+        :versions: 1.0.0
+        :tickets: 3021
+
+        A revisit to this issue first patched in 0.9.5, apparently
+        psycopg2's ``.closed`` accessor is not as reliable as we assumed,
+        so we have added an explicit check for the exception messages
+        "SSL SYSCALL error: Bad file descriptor" and
+        "SSL SYSCALL error: EOF detected" when detecting an
+        is-disconnect scenario.   We will continue to consult psycopg2's
+        connection.closed as a first check.
+
     .. change::
         :tags: bug, orm, engine
         :versions: 1.0.0
index e6450c97fac8524c647d910d6f76e7e3fbbf7a8b..9dfd53e22848539d6719fb75418bab1329a84e79 100644 (file)
@@ -512,12 +512,14 @@ class PGDialect_psycopg2(PGDialect):
     def is_disconnect(self, e, connection, cursor):
         if isinstance(e, self.dbapi.Error):
             # check the "closed" flag.  this might not be
-            # present on old psycopg2 versions
+            # present on old psycopg2 versions.   Also,
+            # this flag doesn't actually help in a lot of disconnect
+            # situations, so don't rely on it.
             if getattr(connection, 'closed', False):
                 return True
 
-            # legacy checks based on strings.  the "closed" check
-            # above most likely obviates the need for any of these.
+            # checks based on strings.  in the case that .closed
+            # didn't cut it, fall back onto these.
             str_e = str(e).partition("\n")[0]
             for msg in [
                 # these error messages from libpq: interfaces/libpq/fe-misc.c
@@ -534,8 +536,10 @@ class PGDialect_psycopg2(PGDialect):
                 # not sure where this path is originally from, it may
                 # be obsolete.   It really says "losed", not "closed".
                 'losed the connection unexpectedly',
-                # this can occur in newer SSL
-                'connection has been closed unexpectedly'
+                # these can occur in newer SSL
+                'connection has been closed unexpectedly',
+                'SSL SYSCALL error: Bad file descriptor',
+                'SSL SYSCALL error: EOF detected',
             ]:
                 idx = str_e.find(msg)
                 if idx >= 0 and '"' not in str_e[:idx]: