Checkbox-SQLAlchemy TimeoutError

My backend configuration:

  • Ubuntu 12.04
  • Python 2.7
  • Flask 0.9
  • Flask-SQLAlchemy
  • Postgres 9.2

I have this error message:

TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30 

Do I need to explicitly close db.session? Shouldn't there be a connection back to the pool when the session goes out of scope?

+4
source share
3 answers

This can happen if you use debug=True in your application and you have loaded several API pages or endpoints that have fallen out of the system.

The reason is that starting the debug version of the application allows you to disable the live debugger on the error page. This live debugger supports all resources from request processing so that you can examine them. This means that the database connection cannot be reworked.

You should not use debugging mode for the production version of your application (except for problems like this, this is a security risk), and the debugger will often not work in any case (it is designed to work with the test server of flacks, and not with machine guns). Therefore, in prod, the solution is to disable debugging.

If you have this problem in dev using debug mode - this is a limitation. You should not hit the dev server so hard, or you can increase the limit. Keep in mind that 15 connections are usually enough to serve a large number of concurrent requests when they are correctly processed. It is only in debugging that they tend to end up.

+5
source

Flask-SQLAlchemy manages the connection pool for you, so overall this is not necessary. However, there are some instances in which it cannot control this, especially if you execute requests outside the request context or somewhere with app.app_context() .

When I paired Flask-SQLAlchemy with apscheduler , I found that I had to explicitly close sessions in tasks performed by the scheduler, or after several hours of operation I would get this error.

+2
source
 @app.teardown_request def checkin_db(exc): try: g.db.close() except AttributeError: pass 
0
source

Source: https://habr.com/ru/post/1481635/


All Articles