I get 500 error when I access a hosted page after some time

I am hosting Redash.
I get a 500 error when I access a hosted page after a period of time. Reloading multiple times fixes it.
Is there any way to fix this problem?

The error log is as follows

May 30 05:19:09 PM  Traceback (most recent call last):  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1249, in _execute_context    cursor, statement, parameters, context  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 580, in do_execute    cursor.execute(statement, parameters)psycopg2.OperationalError: server closed the connection unexpectedly
May 30 05:19:09 PM      This probably means the server terminated abnormally
May 30 05:19:09 PM      before or while processing the request.
May 30 05:19:09 PM  
May 30 05:19:09 PM  
May 30 05:19:09 PM  The above exception was the direct cause of the following exception:
May 30 05:19:09 PM  
May 30 05:19:09 PM  Traceback (most recent call last):  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app    response = self.full_dispatch_request()  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request    rv = self.handle_user_exception(e)  File "/usr/local/lib/python3.7/site-packages/flask_restful/__init__.py", line 269, in error_router    return original_handler(e)  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception    reraise(exc_type, exc_value, tb)  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise    raise value  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1946, in full_dispatch_request    request_started.send(self)  File "/usr/local/lib/python3.7/site-packages/blinker/base.py", line 267, in send    for receiver in self.receivers_for(sender)]  File "/usr/local/lib/python3.7/site-packages/blinker/base.py", line 267, in <listcomp>    for receiver in self.receivers_for(sender)]  File "/app/redash/models/users.py", line 53, in update_user_active_at    if current_user.is_authenticated and not current_user.is_api_user():  File "/usr/local/lib/python3.7/site-packages/werkzeug/local.py", line 348, in __getattr__    return getattr(self._get_current_object(), name)  File "/usr/local/lib/python3.7/site-packages/werkzeug/local.py", line 307, in _get_current_object    return self.__local()  File "/usr/local/lib/python3.7/site-packages/flask_login/utils.py", line 26, in <lambda>    current_user = LocalProxy(lambda: _get_user())  File "/usr/local/lib/python3.7/site-packages/flask_login/utils.py", line 335, in _get_user    current_app.login_manager._load_user()  File "/usr/local/lib/python3.7/site-packages/flask_login/login_manager.py", line 355, in _load_user    return self._load_from_request(request)  File "/usr/local/lib/python3.7/site-packages/flask_login/login_manager.py", line 412, in _load_from_request    user = self.request_callback(request)  File "/app/redash/authentication/__init__.py", line 69, in request_loader    user = api_key_load_user_from_request(request)  File "/app/redash/authentication/__init__.py", line 162, in api_key_load_user_from_request    user = get_user_from_api_key(api_key, query_id)  File "/app/redash/authentication/__init__.py", line 120, in get_user_from_api_key    org = current_org._get_current_object()  File "/usr/local/lib/python3.7/site-packages/werkzeug/local.py", line 307, in _get_current_object    return self.__local()  File "/app/redash/authentication/org_resolving.py", line 18, in _get_current_org    g.org = Organization.get_by_slug(slug)  File "/app/redash/models/organizations.py", line 31, in get_by_slug    return cls.query.filter(cls.slug == slug).first()  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3240, in first    ret = list(self[0:1])  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3018, in __getitem__    return list(res)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3342, in __iter__    return self._execute_and_instances(context)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3367, in _execute_and_instances    result = conn.execute(querycontext.statement, self._params)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 988, in execute    return meth(self, multiparams, params)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 287, in _execute_on_connection    return connection._execute_clauseelement(self, multiparams, params)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1107, in _execute_clauseelement    distilled_params,  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1253, in _execute_context    e, statement, parameters, cursor, context  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1473, in _handle_dbapi_exception    util.raise_from_cause(sqlalchemy_exception, exc_info)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause    reraise(type(exception), exception, tb=exc_tb, cause=cause)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 152, in reraise    raise value.with_traceback(tb)  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1249, in _execute_context    cursor, statement, parameters, context  File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 580, in do_execute    cursor.execute(statement, parameters)sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
May 30 05:19:09 PM      This probably means the server terminated abnormally
May 30 05:19:09 PM      before or while processing the request.
May 30 05:19:09 PM  
May 30 05:19:09 PM  [SQL: SELECT organizations.updated_at AS organizations_updated_at, organizations.created_at AS organizations_created_at, organizations.id AS organizations_id, organizations.name AS organizations_name, organizations.slug AS organizations_slug, organizations.settings AS organizations_settings
May 30 05:19:09 PM  FROM organizations
May 30 05:19:09 PM  WHERE organizations.slug = %(slug_1)s
May 30 05:19:09 PM   LIMIT %(param_1)s]
May 30 05:19:09 PM  [parameters: {'slug_1': 'default', 'param_1': 1}]
May 30 05:19:09 PM  (Background on this error at: http://sqlalche.me/e/e3q8)

My render.yaml is as follows

databases:
  - name: redash-postgres
    databaseName: redash
    user: redash
    region: singapore

services:
  # Do not forget to run `render-redash create_db` in Render Shell after creating this service.
  # If you have upgraded from a previous version, run `render-redash manage db upgrade` instead.
  - type: web
    name: redash-server
    plan: standard
    region: singapore
    env: docker
    dockerCommand: render-redash server
    healthCheckPath: /ping
    envVars:
      - key: PORT
        value: 5000
      - key: REDASH_DATABASE_URL
        fromDatabase:
          name: redash
          property: connectionString
      - key: REDASH_REDIS_URL
        fromService:
          type: redis
          name: redash-redis
          property: connectionString
      - fromGroup: redash-shared
      - fromGroup: redash-mail

  - type: worker
    name: redash-scheduler
    plan: starter
    region: singapore
    env: docker
    dockerCommand: render-redash scheduler
    envVars:
      - key: REDASH_DATABASE_URL
        fromDatabase:
          name: redash
          property: connectionString
      - key: REDASH_REDIS_URL
        fromService:
          type: redis
          name: redash-redis
          property: connectionString
      - fromGroup: redash-shared
      - fromGroup: redash-mail

  - type: worker
    name: redash-worker
    plan: starter
    region: singapore
    env: docker
    dockerCommand: render-redash worker
    envVars:
      - key: REDASH_DATABASE_URL
        fromDatabase:
          name: redash
          property: connectionString
      - key: REDASH_REDIS_URL
        fromService:
          type: redis
          name: redash-redis
          property: connectionString
      - fromGroup: redash-shared
      - fromGroup: redash-mail
      - key: QUEUES
        value: "queries,scheduled_queries,schemas"
      - key: WORKERS_COUNT
        value: 2

  - type: redis
    name: redash-redis
    plan: free
    region: singapore
    maxmemoryPolicy: allkeys-lru
    ipAllowList: []

envVarGroups:
  - name: redash-shared
    envVars:
      - key: REDASH_COOKIE_SECRET
        value: "<secret value>"
      - key: REDASH_SECRET_KEY
        value: "<secret value>"
      - key: REDASH_LOG_LEVEL
        value: "INFO"

  # Uncomment and fill following fields if you wish to set up mailing in Redash.
  # It’s recommended to use some mail service, like Amazon SES or Mailgun
  # to send emails to ensure deliverability.
  - name: redash-mail
    envVars:
#      - key: REDASH_MAIL_SERVER
#        value: (SMTP server address)
#      - key: REDASH_MAIL_PORT
#        value: 25
#      - key: REDASH_MAIL_USE_TLS
#        value: false
#      - key: REDASH_MAIL_USE_SSL
#        value: false
#      - key: REDASH_MAIL_USERNAME
#        value: None
#      - key: REDASH_MAIL_PASSWORD
#        value: None
#      - key: REDASH_MAIL_DEFAULT_SENDER
#        value: (Email address to send from)

Hi,

It looks like your issue is related to this Redash discussion and Redash Github issue. It has already been fixed by Redash contributors.

To enable it, within your render.yaml , under the envVars field of the rediash-server section, add the following:

- key: SQLALCHEMY_ENABLE_POOL_PRE_PING
  value: true

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.