opensemanticsearch / open-semantic-search-apps

Python/Django based webapps and web user interfaces for search, structure (meta data management like thesaurus, ontologies, annotations and named entities) and data import (ETL like text extraction, OCR and crawling filesystems or websites)
https://opensemanticsearch.org/
GNU General Public License v3.0
95 stars 37 forks source link

Sometimes "Internal Server Error" #57

Closed opensemanticsearch closed 5 years ago

opensemanticsearch commented 5 years ago

(Seems especially on newer Debian releases or current installations maybe because newer releases of some dependencies like Debian and/or PIP packages) there is sometimes a "Internal Server Error" but not on every call, so sometimes you have to do multiple/many calls to reproduce it.

Maybe dependency hell of PIP/debian packages? Or an (after evolution of some Python packages using new/other features) now unstable Apache2 config?

Trying to setup WSGI module of Apache to daemon mode (which is recommended by Django).

Mandalka commented 5 years ago

I set the wsgi config for Apache2 to daemon mode, now it works for first IP every time, but calls from another IP get the internal server error every time:

/var/log/apache2/error.log:

[Fri Jul 19 13:42:35.021155 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] mod_wsgi (pid=1198): Failed to exec Python script file '/var/lib/opensemanticsearch/opensemanticsearch/wsgi.py'. [Fri Jul 19 13:42:35.021237 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] mod_wsgi (pid=1198): Exception occurred processing WSGI script '/var/lib/opensemanticsearch/opensemanticsearch/wsgi.py'. [Fri Jul 19 13:42:35.021417 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] Traceback (most recent call last): [Fri Jul 19 13:42:35.021475 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] File "/var/lib/opensemanticsearch/opensemanticsearch/wsgi.py", line 14, in [Fri Jul 19 13:42:35.021489 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] application = get_wsgi_application() [Fri Jul 19 13:42:35.021508 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] File "/usr/lib/python3/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application [Fri Jul 19 13:42:35.021525 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] django.setup(set_prefix=False) [Fri Jul 19 13:42:35.021596 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] File "/usr/lib/python3/dist-packages/django/init.py", line 27, in setup [Fri Jul 19 13:42:35.021609 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] apps.populate(settings.INSTALLED_APPS) [Fri Jul 19 13:42:35.021626 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] File "/usr/lib/python3/dist-packages/django/apps/registry.py", line 78, in populate [Fri Jul 19 13:42:35.021637 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] raise RuntimeError("populate() isn't reentrant") [Fri Jul 19 13:42:35.021682 2019] [wsgi:error] [pid 1198] [remote 10.0.2.2:53382] RuntimeError: populate() isn't reentrant

Mandalka commented 5 years ago

After temporary removing of complex (many dependencies) external import-export-app (throwing (maybe same problem) an error importing numpy) following more OSS specific error on second IP:

Traceback:

File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py" in inner

  1. response = get_response(request)

File "/usr/lib/python3/dist-packages/django/core/handlers/base.py" in _legacy_get_response

  1. response = middleware_method(request)

File "/usr/lib/python3/dist-packages/django/middleware/common.py" in process_request

  1. if self.should_redirect_with_slash(request):

File "/usr/lib/python3/dist-packages/django/middleware/common.py" in should_redirect_with_slash

  1. not is_valid_path(request.path_info, urlconf) and

File "/usr/lib/python3/dist-packages/django/urls/base.py" in is_valid_path

  1. resolve(path, urlconf)

File "/usr/lib/python3/dist-packages/django/urls/base.py" in resolve

  1. return get_resolver(urlconf).resolve(path)

File "/usr/lib/python3/dist-packages/django/urls/resolvers.py" in resolve

  1. for pattern in self.url_patterns:

File "/usr/lib/python3/dist-packages/django/utils/functional.py" in get

  1. res = instance.dict[self.name] = self.func(instance)

File "/usr/lib/python3/dist-packages/django/urls/resolvers.py" in url_patterns

  1. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

File "/usr/lib/python3/dist-packages/django/utils/functional.py" in get

  1. res = instance.dict[self.name] = self.func(instance)

File "/usr/lib/python3/dist-packages/django/urls/resolvers.py" in urlconf_module

  1. return import_module(self.urlconf_name)

File "/usr/lib/python3.7/importlib/init.py" in import_module

  1. return _bootstrap._gcd_import(name[level:], package, level)

File "/var/lib/opensemanticsearch/opensemanticsearch/urls.py" in

  1. url(r'^api/', include('api.urls', namespace="api")),

File "/usr/lib/python3/dist-packages/django/conf/urls/init.py" in include

  1. urlconf_module = import_module(urlconf_module)

File "/usr/lib/python3.7/importlib/init.py" in import_module

  1. return _bootstrap._gcd_import(name[level:], package, level)

File "/var/lib/opensemanticsearch/api/urls.py" in

  1. from api import views

File "/var/lib/opensemanticsearch/api/views.py" in

  1. from opensemanticetl.tasks import delete

File "/usr/lib/python3/dist-packages/opensemanticetl/tasks.py" in

  1. from etl_web import Connector_Web

File "/usr/lib/python3/dist-packages/opensemanticetl/etl_web.py" in

  1. from lxml import etree

Exception Type: ImportError at /files/recrawl Exception Value: Interpreter change detected - this module can only be loaded into one interpreter per process.

Mandalka commented 5 years ago

WSGIApplicationGroup %{GLOBAL} in apache config seems to solve it.

Documentation from https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIApplicationGroup.html

%{GLOBAL}

The application group name will be set to the empty string.

Any WSGI applications in the global application group will always be executed within the context of the first interpreter created by Python when it is initialised, of the process handling the request. Forcing a WSGI application to run within the first interpreter can be necessary when a third party C extension module for Python has used the simplified threading API for manipulation of the Python GIL and thus will not run correctly within any additional sub interpreters created by Python.

Mandalka commented 5 years ago

Changed preconfigured Apache wsgi config of the package in https://github.com/opensemanticsearch/open-semantic-search-apps/commit/9f4e2d710b44cb0b6914710058ee43fe5716ec06