WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.49k stars 993 forks source link

Debug error page crashes on database connection error #11047

Closed justscribe closed 6 months ago

justscribe commented 6 months ago

Describe the issue

When user with IPhone 13 (seems Safari 16) trying to load a project page with a lot of components (60+ pages), uwsgi returns 502 error and never returns until restart.

I already tried

Steps to reproduce the behavior

  1. Login to Weblate through Google.
  2. Open a big project with 60+ page.

Expected behavior

Should load the first page of the project components.

Screenshots

image image

Exception traceback

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/weblate-env/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/root/weblate-env/lib/python3.10/site-packages/weblate/middleware.py", line 65, in __call__
    return self.get_response(request)
  File "/root/weblate-env/lib/python3.10/site-packages/django/core/handlers/exception.py", line 57, in inner
    response = response_for_exception(request, exc)
  File "/root/weblate-env/lib/python3.10/site-packages/django/core/handlers/exception.py", line 143, in response_for_exception
    log_response(
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/log.py", line 241, in log_response
    getattr(logger, level)(
  File "/usr/lib/python3.10/logging/__init__.py", line 1506, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib/python3.10/logging/__init__.py", line 1624, in _log
    self.handle(record)
 File "/usr/lib/python3.10/logging/__init__.py", line 1634, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 968, in handle
    self.emit(record)
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/log.py", line 125, in emit
    reporter.get_traceback_text(),
  File "/root/weblate-env/lib/python3.10/site-packages/django/views/debug.py", line 417, in get_traceback_text
    c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
  File "/root/weblate-env/lib/python3.10/site-packages/rollbar/contrib/django/middleware.py", line 170, in new_get_traceback_data
    data = old_get_traceback_data(exception_reporter)
  File "/root/weblate-env/lib/python3.10/site-packages/django/views/debug.py", line 377, in get_traceback_data
    self.filter.get_post_parameters(self.request).items()
  File "/root/weblate-env/lib/python3.10/site-packages/weblate/trans/debug.py", line 26, in get_post_parameters
    for name, _url, version in get_versions_list():
  File "/root/weblate-env/lib/python3.10/site-packages/weblate/utils/requirements.py", line 217, in get_versions_list
    *get_db_cache_version(),
  File "/root/weblate-env/lib/python3.10/site-packages/weblate/utils/requirements.py", line 205, in get_db_cache_version
    db_version = get_db_version()
  File "/root/weblate-env/lib/python3.10/site-packages/weblate/utils/requirements.py", line 159, in get_db_version
    with connection.cursor() as cursor:
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 330, in cursor
    return self._cursor()
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 306, in _cursor
    self.ensure_connection()
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 288, in ensure_connection
    with self.wrap_database_errors:
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
    self.connect()
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 270, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
    connection = self.Database.connect(**conn_params)
  File "/root/weblate-env/lib/python3.10/site-packages/psycopg/connection.py", line 729, in connect
    raise ex.with_traceback(None)
django.db.utils.OperationalError: connection failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?During handling of the above exception, another exception occurred:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
    self.connect()
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/base/base.py", line 270, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/root/weblate-env/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/weblate-env/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
    connection = self.Database.connect(**conn_params)
  File "/root/weblate-env/lib/python3.10/site-packages/psycopg/connection.py", line 729, in connect
    raise ex.with_traceback(None)
psycopg.OperationalError: connection failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?

[pid: 3938268|app: 0|req: 230/1022] 184.105.139.69 () {36 vars in 538 bytes} [Tue Feb 20 09:09:48 2024] GET /.git/config => generated 0 bytes in 2118 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
Tue Feb 20 09:09:59 2024 - ...brutally killing workers...
Tue Feb 20 09:10:01 2024 - worker 4 buried after 2 seconds
Tue Feb 20 09:10:01 2024 - worker 3 buried after 2 seconds
Tue Feb 20 09:10:02 2024 - worker 1 buried after 3 seconds
Tue Feb 20 09:10:02 2024 - worker 2 buried after 3 seconds
Tue Feb 20 09:10:02 2024 - binary reloading uWSGI...
Tue Feb 20 09:10:02 2024 - chdir() to /
Tue Feb 20 09:10:02 2024 - closing all non-uwsgi socket fds > 2 (max_fd = 1024)...
Tue Feb 20 09:10:02 2024 - found fd 3 mapped to socket 0 (/run/uwsgi/app/weblate/socket)
Tue Feb 20 09:10:02 2024 - found fd 5 mapped to socket 1 (127.0.0.1:8080)
Tue Feb 20 09:10:02 2024 - running /usr/bin/uwsgi-core
[uWSGI] getting INI configuration from /usr/share/uwsgi/conf/default.ini
[uWSGI] getting INI configuration from /etc/uwsgi/apps-enabled/weblate.ini
Tue Feb 20 09:10:02 2024 - *** Starting uWSGI 2.0.20-debian (64bit) on [Tue Feb 20 09:10:02 2024] ***

These exceptions just spamming all the log for uwsgi.

How do you run Weblate?

PyPI module

Weblate versions

(weblate-env) root@localhost:~# weblate list_versions

Weblate deploy checks

(weblate-env) root@localhost:~# weblate check --deploy
INFO:weblate.errors:configured Rollbar error collection
System check identified no issues (1 silenced).

Additional context

On Android phones and Desktop Chrome browsers works fine.

nijel commented 6 months ago

psycopg.OperationalError: connection failed: Connection refused

Maybe you're hitting connection limit on the PostgreSQL server? Or there is another reason why it rejects new connection, but this seems to be outside Weblate.

The exception traceback you've posted is from rendering the debug error page, there should be another exception above which is the actual root cause. I'm going to fix the bug in the debug error page now. If the above exception is different from a PostgreSQL connection error, please open a separate issue with it.

github-actions[bot] commented 6 months ago

Thank you for your report; the issue you have reported has just been fixed.