Flask + Postgres keeps failing with SSL SYSCALL error

Viewed 93

My Flask app connection with a Heroku/AWS postgres DB keeps intermittently failing with the following error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL SYSCALL error: EOF detected

The error happens only after the app has been idle for a few minutes.

The db connection is flask is very straightforward:

from flask_sqlalchemy import SQLAlchemy
app.config.from_object(Config())
db = SQLAlchemy()
db.init_app(app)

and the Config file simply retrieves the DATABASE_URL from the environment variable:

SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')

I suspect I may be missing a configuration setting somewhere either on Heroku or in my Flask app to make this work?

0 Answers
Related