sanic+tortoise-orm, A worker process was unable to process subsequent requests due to asyncio.exceptions.CancelledError

42 views Asked by At
await Students.filter(id_nunmber = data.id_nunmber, deleted = False).first()

When I execute the above code line without an index, timeout raises the asyncio error:

[2024-01-13 14:03:56,180] [sanic.root] [ERROR] [T-140573585867200] [handlers.py:129-default]  Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/sanic/http/http1.py", line 127, in http1
    await self.protocol.request_handler(self.request)
  File "handle_request", line 97, in handle_request
  File "/usr/local/lib/python3.10/dist-packages/sanic_ext/extras/validation/decorator.py", line 74, in decorated_function
    retval = await retval
  File "/data/www/wanji_art_exam/app/controllers/apply_exam.py", line 33, in check_list_apply_exam
    result = await ApplyExamService.check_list(body, current_user)
  File "/data/www/wanji_art_exam/app/services/apply_exam.py", line 226, in check_list
    result = await cls.check_applyexam_data(req)
  File "/data/www/wanji_art_exam/app/services/apply_exam.py", line 206, in check_applyexam_data
    student:Students = await Students.filter(id_nunmber = data.id_nunmber, deleted = False).first()
  File "/usr/local/lib/python3.10/dist-packages/tortoise/queryset.py", line 1008, in _execute
    instance_list = await self._db.executor_class(
  File "/usr/local/lib/python3.10/dist-packages/tortoise/backends/base/executor.py", line 131, in execute_select
    _, raw_results = await self.db.execute_query(query.get_sql())
  File "/usr/local/lib/python3.10/dist-packages/tortoise/backends/mysql/client.py", line 44, in translate_exceptions_
    return await func(self, *args)
  File "/usr/local/lib/python3.10/dist-packages/tortoise/backends/mysql/client.py", line 199, in execute_query
    await cursor.execute(query, values)
  File "asyncmy/cursors.pyx", line 179, in execute
  File "asyncmy/cursors.pyx", line 364, in _query
  File "asyncmy/connection.pyx", line 450, in query
  File "asyncmy/connection.pyx", line 638, in _read_query_result
  File "asyncmy/connection.pyx", line 1032, in read
  File "asyncmy/connection.pyx", line 1102, in _read_result_packet
  File "asyncmy/connection.pyx", line 1172, in _get_descriptions
  File "asyncmy/connection.pyx", line 588, in read_packet
  File "asyncmy/connection.pyx", line 612, in _read_bytes
  File "/usr/lib/python3.10/asyncio/streams.py", line 708, in readexactly
    await self._wait_for_data('readexactly')
  File "/usr/lib/python3.10/asyncio/streams.py", line 501, in _wait_for_data
    await self._waiter
asyncio.exceptions.CancelledError: Cancel connection task with a timeout

I know this error is necessary, but it should not destroy the whole process.

I checked the code, and maybe this error was raised by tortoise-orm connection broken, but I have no idea how to solve this problem, Can someone help me? Thanks!

1

There are 1 answers

0
heysaeid92 On

If you are confident about the correctness of the connection string and database access, update the psycopg2-binary version to the latest. I resolved the issue with the installation of the following version:

pip install -U psycopg2-binary==2.9.9