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

Better handling of database connection errors #61

Open
martijnvermaat opened this issue Jul 17, 2015 · 0 comments
Open

Better handling of database connection errors #61

martijnvermaat opened this issue Jul 17, 2015 · 0 comments

Comments

@martijnvermaat
Copy link
Contributor

For example, restarting the PostgreSQL server, I could trigger the following SQLAlchemy exception:

Exception on /description-extractor [POST]
Traceback (most recent call last):
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/mutalyzer/website/views.py", line 739, in description_extractor_submit
    genbank_record = retriever.loadrecord(reference_accession_number)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/mutalyzer/Retriever.py", line 772, in loadrecord
    .filter_by(accession=identifier) \
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2367, in first
    ret = list(self[0:1])
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2228, in __getitem__
    return list(res)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2438, in __iter__
    return self._execute_and_instances(context)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2453, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 729, in execute
    return meth(self, multiparams, params)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
    context)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1159, in _handle_dbapi_exception
    exc_info
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
    context)
  File "/opt/mutalyzer/virtualenv/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
    cursor.execute(statement, parameters)
OperationalError: (OperationalError) terminating connection due to administrator command
SSL connection has been closed unexpectedly

Instead of resulting in an internal server error, it would probably be better to respond with a helpful error message and status 503 Service Unavailable. Especially for the web services, this would allow clients to handle this in the same way as the maintenance status, also using 503.

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

1 participant