0

Please I need help with the following error which I get on the 16th database connection. None of the other answers on Stackoverflow seem to work:

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

Backend configuration:

  • Python 2.6.9
  • Flask 0.10.1
  • Flask-SQLAlchemy 2.1
  • Mysql-connector-python 1.0.12
  • Mysql 5.6.27

Database Setup:

connection_str = 'mysql+mysqlconnector://%s:%s@%s:%s/%s' % (config["DATABASE_USER"], config["DATABASE_PASSWORD"], \
                                                            config["DATABASE_HOST"], config["DATABASE_PORT"], \
                                                            config["DATABASE_SCHEMA1"])
engine = create_engine(connection_str, convert_unicode=True, pool_recycle=config["DATABASE_POOL_RECYCLE"])
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()

import application_package.models
Base.metadata.create_all(bind=engine)


@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()
2
  • What is your application doing that your connections are all active for 30+ seconds? Commented Jul 10, 2016 at 20:38
  • The application does not need the connection for 30+ seconds. It seems like for some reason, the connections don't get returned to the pool after each request. When all connections get used up, it unsuccessfully waits for 30seconds for an available connection before throwing that error. Commented Jul 11, 2016 at 4:51

1 Answer 1

1

I've realized the problem is that I created a separate threadpool with threads that weren't terminating and were keeping all my database connections open even after the response has been returned to the client. This was a bad hack and terrible idea. I intend to get rid of this threadpool and use celery to schedule asynchronous tasks.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.