Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redsah returns HTTP 500 after PostgreSQL connection was closed #3817

Open
citrin opened this issue May 21, 2019 · 2 comments
Open

Redsah returns HTTP 500 after PostgreSQL connection was closed #3817

citrin opened this issue May 21, 2019 · 2 comments

Comments

@citrin
Copy link
Contributor

citrin commented May 21, 2019

Issue Summary

Redsah returns HTTP 500 after PostgreSQL connection was closed, e. g. if PostgreSQL was restarted.

Steps to Reproduce

  1. Restart PostgreSQL
  2. Send HTTP request to redash.

Technical details:

  • Redash Version: 7.0.0
  • Browser/OS: Any/Linux
  • How did you install Redash: using Docker

It is easy to fix this issue by using pre-ping in SQLAlchemy

diff --git redash/settings/__init__.py redash/settings/__init__.py
index efb2a1cd..8e00fc9f 100644
--- redash/settings/__init__.py
+++ redash/settings/__init__.py
@@ -29,6 +29,10 @@ SQLALCHEMY_DATABASE_URI = os.environ.get("REDASH_DATABASE_URL", os.environ.get('
 SQLALCHEMY_MAX_OVERFLOW = int_or_none(os.environ.get("SQLALCHEMY_MAX_OVERFLOW"))
 SQLALCHEMY_POOL_SIZE = int_or_none(os.environ.get("SQLALCHEMY_POOL_SIZE"))
 SQLALCHEMY_DISABLE_POOL = parse_boolean(os.environ.get("SQLALCHEMY_DISABLE_POOL", "false"))
+SQLALCHEMY_ENGINE_OPTIONS = {
+    # https://docs.sqlalchemy.org/en/13/core/pooling.html#pool-disconnects
+    'pool_pre_ping': True,
+}
 SQLALCHEMY_TRACK_MODIFICATIONS = False
 SQLALCHEMY_ECHO = False

diff --git requirements.txt requirements.txt
index b3b0d668..c56bd668 100644
--- requirements.txt
+++ requirements.txt
@@ -12,7 +12,7 @@ Flask-Login==0.4.0
 Flask-OAuthLib==0.9.5
 # pin this until https://github.com/lepture/flask-oauthlib/pull/388 is released
 requests-oauthlib>=0.6.2,<1.2.0
-Flask-SQLAlchemy==2.3.2
+Flask-SQLAlchemy==2.4.0
 Flask-Migrate==2.0.1
 flask-mail==0.9.1
 flask-sslify==0.1.5

Flask-SQLAlchemy 2.4.0 deprecated a few settings - they should be moved to SQLALCHEMY_ENGINE_OPTIONS too.

@arikfr
Copy link
Member

arikfr commented May 21, 2019

If you were to run a new request after this, will it error again?

@citrin
Copy link
Contributor Author

citrin commented May 22, 2019

No, this errors happens only on a first request (or a few first requests) after database connection was closed. Then redash reconnects to PostgreSQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants