I wonder if someone had this issue before.
I have an application running with Python 3.7.3, SqlAlchemy and Falcon running in a Docker container.
My database is MariaDB also running in a docker container.
I setup SqlAlchemy pool_recycle
to 3600 but it still drops connection from time to time.
I can't see anything in the logs but the SQLAlchemy log stating connection has been lost after trying to perform some query.
Where could be the issue? SQLAlchemy configuration? MariaDB? Maybe Docker? How can I inspect that?
My repository:
class NfeRepositorio:
def __init__(self, db_session: sessionmaker):
self.session_factory = scoped_session(db_session)
self._session = None
def __enter__(self):
return self
def __exit__(self, ex_type, ex_value, ex_traceback):
self.session_factory.remove()
@property
def session(self):
if not self._session:x
self._session = self.session_factory()
return self._session
My engine setup:
orm_engine = create_engine(
get_config().ORM_ENGINE_TEMPLATE.format(
get_config().DB_PROTOCOL,
get_config().DB_USERNAME,
get_config().DB_PASSWORD,
get_config().DB_HOST,
get_config().DB_NAME
),
echo=get_config().ORM_ECHO,
pool_recycle=3600
)
Edit 1:
Just found a log entry and did some research on Google. Several people having the same issue.
[Warning] Aborted connection to db (Got timeout reading communication packets)
Looks like the issue relates with the difference between SqlAlchemy session and MySql session. The SO post below explains better. How to close a SQLAlchemy session?
I'll give it a try and post the results.