Reported by Werner for Uni Münster.
Log files show that the server closed the connection unexpectedly (see traceback).
The application is running in a k8s cluster, and it could likely be associated with the connection pooling. Here's a possible solution is described using the pool_pre_ping
.
One possible approach would be to boot up e.g. an InvenioRDM. Browse a couple of pages. Then, restart the database server.
[2021-03-05 12:09:14,264] ERROR in app: Exception on /records [GET]
Traceback (most recent call last):
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1277, in _execute_context
cursor, statement, parameters, context
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
psycopg2.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_restful/__init__.py", line 272, in error_router
return original_handler(e)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/views/base.py", line 51, in dispatch_request
return view(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/context.py", line 71, in inner
return f(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/parsers/base.py", line 44, in inner
return f(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/content_negotiation.py", line 106, in inner
return f(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/responses.py", line 30, in wrapper
return f(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/context.py", line 87, in inner
return f(*args)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/parsers/base.py", line 44, in inner
return f(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/loaders.py", line 59, in wrapper
return f(self, *args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask/views.py", line 163, in dispatch_request
return meth(*args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_resources/views/collections.py", line 43, in get
*self.resource.search(*args, **kwargs)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/invenio_records_resources/resources/records/resource.py", line 51, in search
es_preference=self._get_es_preference()
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/invenio_records_resources/services/records/service.py", line 167, in search
self.require_permission(identity, 'search')
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/invenio_records_resources/services/base/service.py", line 44, in require_permission
if not self.permission_policy(action_name, **kwargs).allows(identity):
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/flask_principal.py", line 333, in allows
if self.needs and not self.needs.intersection(identity.provides):
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/invenio_records_permissions/policies/base.py", line 89, in needs
self._load_permissions() # self.explicit_needs is used here
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/invenio_access/permissions.py", line 169, in _load_permissions
result.update(self._expand_action(need))
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/invenio_access/permissions.py", line 191, in _expand_action
actionsusers = ActionUsers.query_by_action(explicit_action).all()
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/orm/query.py", line 3373, in all
return list(self)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
return self._execute_and_instances(context)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1130, in _execute_clauseelement
distilled_params,
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1317, in _execute_context
e, statement, parameters, cursor, context
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1511, in _handle_dbapi_exception
sqlalchemy_exception, with_traceback=exc_info[2], from_=e
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
raise exception
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1277, in _execute_context
cursor, statement, parameters, context
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
[SQL: SELECT access_actionsusers.id AS access_actionsusers_id, access_actionsusers.action AS access_actionsusers_action, access_actionsusers.exclude AS access_actionsusers_exclude, access_actionsusers.argument AS access_actionsusers_argument, access_actionsusers.user_id AS access_actionsusers_user_id
FROM access_actionsusers
WHERE access_actionsusers.action = %(action_1)s AND access_actionsusers.argument IS NULL]
[parameters: {'action_1': 'superuser-access'}]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
[pid: 15|app: 0|req: 128/309] 10.51.216.206 () {56 vars in 797 bytes} [Fri Mar 5 12:09:14 2021] GET /api/records => generated 182 bytes in 20 msecs (HTTP/1.1 500) 13 headers in 644 bytes (1 switches on core 3)