Timeout Issue in API Access Request

Hi,

I’m trying to request an API Access through the /api-admin/ endpoint but I’m getting a Timeout issue with the log details below. It seems that it can’t connect to the MySQL, but so far the connection is fine through direct cli access, also other settings are set like the API Access Configs in /admin/api_admin/ endpoint. In addition, creating course contents and user accounts are also working just fine.

I would appreciate any tips on how to solve this issue.

Thank you!

2022-03-03 07:46:51,262 INFO 23 [tracking] [user 4] [ip xxxx:52820] logger.py:41 - {"name": "/api-admin/", "context": {"user_id": 4, "path": "/api-admin/", "course_id": "", "org_id": "", "enterprise_uuid": ""}, "username": "Super-admin", "session": "b8f8b0e7c3cb863b28b7152a3cf58aa6", "ip": "10.244.1.112", "agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36", "host": "lms.XXX.com", "referer": https://lms.XXXX.com/api-admin/, "accept_language": "en-US,en;q=0.9", "event": "{\"GET\": {}, \"POST\": {\"csrfmiddlewaretoken\": [\"WzvqsDsrcLiM6XKLR1SaysZKTsaiHTC0rGL1kTY0avR83xAKsAgy1oOI3FlC86sj\"], \"company_name\": [\"XXXXX\"], \"website\": [\https://www.XXX.com\], \"company_address\": [\"APAC\"], \"reason\": [\"Cyber\"], \"terms_of_service\": [\"on\"]}}", "time": "2022-03-03T07:46:51.262460+00:00", "event_type": "/api-admin/", "event_source": "server", "page": null}
2022-03-03 07:47:42,346 ERROR 23 [root] [user None] [ip None] signals.py:22 - Uncaught exception from None
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')

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

Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/pyenv/versions/3.8.12/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/openedx/edx-platform/./openedx/core/djangoapps/api_admin/decorators.py", line 19, in wrapped_view
    return view_func(view_obj, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/edit.py", line 172, in post
    return super().post(request, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/edit.py", line 142, in post
    return self.form_valid(form)
  File "/openedx/edx-platform/./openedx/core/djangoapps/api_admin/views.py", line 48, in form_valid
    return super().form_valid(form)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/edit.py", line 125, in form_valid
    self.object = form.save()
  File "/openedx/venv/lib/python3.8/site-packages/django/forms/models.py", line 468, in save
    self.instance.save()
  File "/openedx/venv/lib/python3.8/site-packages/model_utils/models.py", line 38, in save
    super().save(*args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 776, in save_base
    updated = self._save_table(
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 881, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 919, in _do_insert
    return manager._insert(
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
    cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')
2022-03-03 07:47:42,871 ERROR 23 [django.request] [user 4] [ip xxxx:52820] log.py:224 - Internal Server Error: /api-admin/
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')

Hello @romeoobane,

I encounter the same issue but not with the API endpoint, was trying to write user details in the DB.

You can do 2 things:

  1. You can check the output of the InnoDB engine. Here you will get the queries that will be failing. Hit those queries manually from the MySQL shell and check whether it is working.

or

  1. Restart your MySQL service/container and hit your query again, and check whether it is working. Sometimes due to some zombie process, it happens.

Hello @jramnai,

I appreciate your suggestions, so far the queries are working, also have restarted the MySQL service but the issue still there. Will keep looking for solutions.

Thanks again.

1 Like

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