Our application was working fine till we ported to Microsoft database for PostgreSQL in Azure. Then periodically, our application fails for no real reason and we have SSL SYSCALL errors all over the place - on DELETE's and so on. We have tried everything described in the internet- use keepalive args, RAM, memory and everything else . We want to try automatically reestablishing the connection. But we have a threaded connection pool. have looked at this thread Psycopg2 auto reconnect inside a class But our functions that read the database are in another class. So we have two questions:
1)What is the cause of the SSL SYSCALL errors . I have searched all threads and the usual suspects are ruled out. 2)How do i reconnect on failure inside a threaded connection pool class--> this is being used in a flask app
Here is how our app is structured
class DBClass(object):
_instance = None
conn= None
def __new__(cls):
if cls._instance is None:
cls._instance = object.__new__(cls)
try:
max_conn = 12
keepalive_args = { "keepalives": 1, "keepalives_idle": 25, "keepalives_interval": 4,"keepalives_count": 9,
}
db._instance.pool = psycopg2.pool.ThreadedConnectionPool(3, max_conn, db=,
host=, user=,
password=,
port=, **keepalive_args)
except Exception as ex:
db._instance = None
raise ex
return cls._instance
def __enter__(self):
self.conn= self._instance.pool.getconn()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self._instance.pool.putconn(self.connection)
def __del__(self):
self._instance.pool.closeall()
#another python module has a class called clsEmployee. We have dozens of functions using the above-mentioned database class. Something like this.
with DBClass() as db:
pg_conn = db.connection
cur = pg_conn.cursor()
cur.execute("SELECT * from emp")
row = cur.fetchone()[0]