Reputation: 51
While using Flask-SQLAlchemy I get the error 'QueuePool limit of size 10 overflow 10 reached, connection timed out' consistently, after some time. I tried to increase connection pool size, but it only deferred the problem.
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
initialize_db(app)
db = SQLAlchemy()
def initialize_db(app):
db.init_app(app)
SQLALCHEMY_POOL_SIZE = 100
Upvotes: 3
Views: 4049
Reputation: 12252
I just had this issue.
My situation
debug=False
in my app.run()
, so it wasn't being caused by debug=True
, which is something suggested elsewhere.How I fixed it
The problem went away when I got rid of threaded=True
in my app.run()
.
app.run(debug=False, threaded=True)
app.run(debug=False)
Upvotes: 0
Reputation: 51
I figured out the problem. The issue was sometimes database connection was going to lost state, which is causing pool size to be Exhausted after some interval.
To fix the issue I made the MySQL server configuration change for query timeout and made it 1 second.
After 1 second if the query didn't respond it will throw Exception and I added except block in code where that query was invoked(In my case it was GET query). In the Except block, I issued rollback command.
Upvotes: 2