summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql
diff options
context:
space:
mode:
authorZeke Brechtel <5767468+zkl2@users.noreply.github.com>2021-09-25 14:43:28 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-10-05 12:46:22 -0400
commit70cc67c3e6a123cf8210c041e5d23cbc30594ced (patch)
treedd7a1ef008fa9830545315aba36d8b1d50af681d /test/dialect/postgresql
parent5479799e8b3930de706e4ce6a114bad374db245e (diff)
downloadsqlalchemy-70cc67c3e6a123cf8210c041e5d23cbc30594ced.tar.gz
Handle SSL SYSCALL error: Bad Address in postgresql/pyscopg2
Added a "disconnect" condition for the "SSL SYSCALL error: Bad address" error message as reported by psycopg2. Pull request courtesy Zeke Brechtel. Fixes: #5387 Closes: #7087 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7087 Pull-request-sha: 66af76a107a22d9119edc8edcacc1e4ef66dc50d Change-Id: Ia4afc9683b8175a8ca282e07e0f83c65657544ab
Diffstat (limited to 'test/dialect/postgresql')
-rw-r--r--test/dialect/postgresql/test_dialect.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py
index 155019aae..c0eb4410c 100644
--- a/test/dialect/postgresql/test_dialect.py
+++ b/test/dialect/postgresql/test_dialect.py
@@ -255,6 +255,42 @@ $$ 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 = 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",
+ # 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 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"