]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
adding SSL SYSCALL error: Bad address + dialect testing
authorZeke Brechtel <5767468+zkl2@users.noreply.github.com>
Sun, 12 Sep 2021 17:00:37 +0000 (11:00 -0600)
committerZeke Brechtel <5767468+zkl2@users.noreply.github.com>
Sun, 12 Sep 2021 17:00:37 +0000 (11:00 -0600)
lib/sqlalchemy/dialects/postgresql/psycopg2.py
test/dialect/postgresql/test_dialect.py

index e28c01f113d44effd57db6e9dc55cf28dedf5de2..4b86b6ade009496489f845e076247fc56c6bf234 100644 (file)
@@ -1041,15 +1041,13 @@ class PGDialect_psycopg2(PGDialect):
                 # psycopg2/cursor.h
                 "connection already closed",
                 "cursor already closed",
-                # not sure where this path is originally from, it may
-                # be obsolete.   It really says "losed", not "closed".
-                "losed the connection unexpectedly",
                 # these can occur in newer SSL
                 "connection has been closed unexpectedly",
+                "SSL error: decryption failed or bad record mac",
                 "SSL SYSCALL error: Bad file descriptor",
                 "SSL SYSCALL error: EOF detected",
-                "SSL error: decryption failed or bad record mac",
                 "SSL SYSCALL error: Operation timed out",
+                "SSL SYSCALL error: Bad address",
             ]:
                 idx = str_e.find(msg)
                 if idx >= 0 and '"' not in str_e[:idx]:
index a86da8ce7d744ea565b96693f4aacbf59f0091e3..a5f87b9f8671b4ee6297047ee5729ae1a3272e0e 100644 (file)
@@ -255,6 +255,44 @@ $$ LANGUAGE plpgsql;"""
         eq_(cargs, [])
         eq_(cparams["host"], "hostA:portA,hostB,hostC")
 
+    def test_psycopg2_disconnect(self):
+        
+        class Error(Exception):
+            pass
+
+        dbapi = mock.Mock()
+        dbapi.Error = Error
+
+        # dialect = getattr(pscyopg2_dialect, dialect_name).dialect(dbapi=dbapi)
+        dialect = psycopg2_dialect.dialect(dbapi=dbapi)
+        
+        for error in [
+            # these error messages from libpq: interfaces/libpq/fe-misc.c
+            # and interfaces/libpq/fe-secure.c.
+            "terminating connection",
+            "closed the connection",
+            "connection not open",
+            "could not receive data from server",
+            "could not send data to server",
+            # psycopg2 client errors, psycopg2/conenction.h,
+            # psycopg2/cursor.h
+            "connection already closed",
+            "cursor already closed",
+            # these can occur in newer SSL
+            "connection has been closed unexpectedly",
+            "SSL error: decryption failed or bad record mac",
+            "SSL SYSCALL error: Bad file descriptor",
+            "SSL SYSCALL error: EOF detected",
+            "SSL SYSCALL error: Operation timed out",
+            "SSL SYSCALL error: Bad address",
+        ]:
+            eq_(dialect.is_disconnect(
+                Error(error),
+                None, None), True)
+
+        eq_(dialect.is_disconnect("not an error", None, None), False)
+
+
 
 class PGCodeTest(fixtures.TestBase):
     __only_on__ = "postgresql"