From: David H. Irving Date: Fri, 21 Jun 2024 17:57:37 +0000 (-0700) Subject: Handle "SSL SYSCALL error: Success" in psycopg2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63ad54e49dc3daa459caa29da8cffcb3e47a3f8c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Handle "SSL SYSCALL error: Success" in psycopg2 It is now considered a pool-invalidating disconnect event when psycopg2 throws an "SSL SYSCALL error: Success" error message, which can occur when the SSL connection to Postgres is terminated abnormally. Fixes: #11522 --- diff --git a/doc/build/changelog/unreleased_20/11522.rst b/doc/build/changelog/unreleased_20/11522.rst new file mode 100644 index 0000000000..279197a779 --- /dev/null +++ b/doc/build/changelog/unreleased_20/11522.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, postgresql + :tickets: 11522 + + It is now considered a pool-invalidating disconnect event when psycopg2 + throws an "SSL SYSCALL error: Success" error message, which can occur when + the SSL connection to Postgres is terminated abnormally. \ No newline at end of file diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 6c492a5b25..6d4e8e1c7d 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -866,6 +866,12 @@ class PGDialect_psycopg2(_PGDialect_common_psycopg): "SSL SYSCALL error: EOF detected", "SSL SYSCALL error: Operation timed out", "SSL SYSCALL error: Bad address", + # This can occur in OpenSSL 1 when an unexpected EOF occurs. + # https://www.openssl.org/docs/man1.1.1/man3/SSL_get_error.html#BUGS + # It may also occur in newer OpenSSL for a non-recoverable I/O + # error as a result of a system call that does not set 'errno' + # in libc. + "SSL SYSCALL error: Success", ]: idx = str_e.find(msg) if idx >= 0 and '"' not in str_e[:idx]: diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index eae1b55d6e..3f55c085fb 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -365,6 +365,7 @@ $$ LANGUAGE plpgsql;""" "SSL SYSCALL error: EOF detected", "SSL SYSCALL error: Operation timed out", "SSL SYSCALL error: Bad address", + "SSL SYSCALL error: Success", ]: eq_(dialect.is_disconnect(Error(error), None, None), True)