title: SQLAlchemy connection dropping
body: <p>I wonder if someone had this issue before.</p>
  
  <p>I have an application running with Python 3.7.3, SqlAlchemy and Falcon running in a Docker container.</p>
  
  <p>My database is MariaDB also running in a docker container.</p>
  
  <p>I setup SqlAlchemy <code>pool_recycle</code> to 3600 but it still drops connection from time to time.</p>
  
  <p>I can't see anything in the logs but the SQLAlchemy log stating connection has been lost after trying to perform some query.</p>
  
  <p>Where could be the issue? SQLAlchemy configuration? MariaDB? Maybe Docker?
  How can I inspect that?</p>
  
  <p>My repository:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>My engine setup:</p>
  
  <pre><code>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
  )
  </code></pre>
  
  <p><strong>Edit 1</strong>:
  Just found a log entry and did some research on Google. Several people having the same issue. 
  <code>[Warning] Aborted connection to db (Got timeout reading communication packets)</code></p>
  
  <p>Looks like the issue relates with the difference between SqlAlchemy session and MySql session. The SO post below explains better.
  <a href="https://stackoverflow.com/questions/21738944/how-to-close-a-sqlalchemy-session">How to close a SQLAlchemy session?</a></p>
  
  <p>I'll give it a try and post the results.</p>