title: Getting a H12 error on Heroku when app runs fine on localhost
body: <p>Currently I am using flask-sqlalchemy with postgres to run my app on heroku. The app launches and works fine for a while but after about 35 database queries I get the h12 error shown below. After this, no more queries work until I restart the app. I am not doing any heavy database operations at the moment - just simple queries to get the information in the database. I have also displayed my current app configurations below. Any help would be much appreciated! I am really stuck right now!</p>
  <p>Here are my app configurations:</p>
  <pre><code>app = Flask(__name__)
  
  app.secret_key = 'secret'
  
  
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  app.config['SQLALCHEMY_DATABASE_URI'] = &quot;url...&quot;
  app.config['UPLOAD_FOLDER'] = &quot;static/images&quot;
  SQLALCHEMY_ENGINE_OPTIONS = {
      &quot;max_overflow&quot;: 50,
      &quot;pool_pre_ping&quot;: True,
      &quot;pool_recycle&quot;: 60 * 60,
      &quot;pool_size&quot;: 50,
  }
  db = SQLAlchemy(app)
  </code></pre>
  <p>Here is the error:</p>
  <pre><code>at=error code=H12 desc=&quot;Request timeout&quot; method=POST path=&quot;/&quot; host=book-reviews.herokuapp.com request_id=4782bce4-d3d1-4f02-88c2-d8b7a752f9f1 fwd=&quot;46.139.103.215&quot; dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
  2022-08-05T07:37:22.027257+00:00 app[web.1]: [2022-08-05 07:37:22,026] ERROR in app: Exception on / [POST]
  2022-08-05T07:37:22.027267+00:00 app[web.1]: Traceback (most recent call last):
  2022-08-05T07:37:22.027268+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/flask/app.py&quot;, line 2077, in wsgi_app
  2022-08-05T07:37:22.027269+00:00 app[web.1]:     response = self.full_dispatch_request()
  2022-08-05T07:37:22.027271+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/flask/app.py&quot;, line 1525, in full_dispatch_request
  2022-08-05T07:37:22.027271+00:00 app[web.1]:     rv = self.handle_user_exception(e)
  2022-08-05T07:37:22.027271+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/flask/app.py&quot;, line 1523, in full_dispatch_request
  2022-08-05T07:37:22.027272+00:00 app[web.1]:     rv = self.dispatch_request()
  2022-08-05T07:37:22.027272+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/flask/app.py&quot;, line 1509, in dispatch_request
  2022-08-05T07:37:22.027272+00:00 app[web.1]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  2022-08-05T07:37:22.027273+00:00 app[web.1]:   File &quot;/app/application.py&quot;, line 44, in index
  2022-08-05T07:37:22.027274+00:00 app[web.1]:     if (current_user.verify()):
  2022-08-05T07:37:22.027274+00:00 app[web.1]:   File &quot;/app/application.py&quot;, line 389, in verify
  2022-08-05T07:37:22.027275+00:00 app[web.1]:     user = User.query.filter_by(username = self.username).first()
  2022-08-05T07:37:22.027275+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/orm/query.py&quot;, line 2819, in first
  2022-08-05T07:37:22.027276+00:00 app[web.1]:     return self.limit(1)._iter().first()
  2022-08-05T07:37:22.027276+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/orm/query.py&quot;, line 2903, in _iter
  2022-08-05T07:37:22.027277+00:00 app[web.1]:     result = self.session.execute(
  2022-08-05T07:37:22.027277+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/orm/session.py&quot;, line 1711, in execute
  2022-08-05T07:37:22.027277+00:00 app[web.1]:     conn = self._connection_for_bind(bind)
  2022-08-05T07:37:22.027278+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/orm/session.py&quot;, line 1552, in _connection_for_bind
  2022-08-05T07:37:22.027278+00:00 app[web.1]:     return self._transaction._connection_for_bind(
  2022-08-05T07:37:22.027279+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/orm/session.py&quot;, line 747, in _connection_for_bind
  2022-08-05T07:37:22.027279+00:00 app[web.1]:     conn = bind.connect()
  2022-08-05T07:37:22.027279+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/engine/base.py&quot;, line 3234, in connect
  2022-08-05T07:37:22.027280+00:00 app[web.1]:     return self._connection_cls(self, close_with_result=close_with_result)
  2022-08-05T07:37:22.027280+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/engine/base.py&quot;, line 96, in __init__
  2022-08-05T07:37:22.027280+00:00 app[web.1]:     else engine.raw_connection()
  2022-08-05T07:37:22.027281+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/engine/base.py&quot;, line 3313, in raw_connection
  2022-08-05T07:37:22.027281+00:00 app[web.1]:     return self._wrap_pool_connect(self.pool.connect, _connection)
  2022-08-05T07:37:22.027281+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/engine/base.py&quot;, line 3280, in _wrap_pool_connect
  2022-08-05T07:37:22.027282+00:00 app[web.1]:     return fn()
  2022-08-05T07:37:22.027283+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/pool/base.py&quot;, line 310, in connect
  2022-08-05T07:37:22.027283+00:00 app[web.1]:     return _ConnectionFairy._checkout(self)
  2022-08-05T07:37:22.027283+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/pool/base.py&quot;, line 868, in _checkout
  2022-08-05T07:37:22.027284+00:00 app[web.1]:     fairy = _ConnectionRecord.checkout(pool)
  2022-08-05T07:37:22.027284+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/pool/base.py&quot;, line 476, in checkout
  2022-08-05T07:37:22.027284+00:00 app[web.1]:     rec = pool._do_get()
  2022-08-05T07:37:22.027284+00:00 app[web.1]:   File &quot;/app/.heroku/python/lib/python3.10/site-packages/sqlalchemy/pool/impl.py&quot;, line 134, in _do_get
  2022-08-05T07:37:22.027284+00:00 app[web.1]:     raise exc.TimeoutError(
  2022-08-05T07:37:22.027285+00:00 app[web.1]: sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30.00 (Background on this error at: https://sqlalche.me/e/14/3o7r)
  </code></pre>
  <p>And finally here are some examples of the queries I am doing(In case it helps):</p>
  <pre><code>names = Book.query.with_entities(Book.title).all()
  pictures = Book.query.with_entities(Book.image).all()
  bookObject = Book.query.filter_by(book_id = book).first()
  comments = Comments.query.filter_by(book_id = book).all()
  </code></pre>
  <p>Thank you in advance!</p>