高级编排中,使用到了函数节点,在调试高级编排时报错,查看执行详情,错误显示 connection already closed.
查看服务运行报错日志,如下:
POST /api/application/chat_workflow/open HTTP/1.1" 200 88
Traceback (most recent call last):
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 308, in _cursor
return self._prepare_cursor(self.create_cursor(name))
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/postgresql/base.py”, line 330, in create_cursor
cursor = self.connection.cursor()
^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.InterfaceError: connection already closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/opt/maxkb/app/apps/application/flow/workflow_manage.py”, line 363, in hand_event_node_result
current_result = node_result_future.result()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/maxkb/app/apps/application/flow/workflow_manage.py”, line 176, in result
raise self.e
File “/opt/maxkb/app/apps/application/flow/workflow_manage.py”, line 400, in run_node_future
node.valid_args(node.node_params, node.workflow_params)
File “/opt/maxkb/app/apps/application/flow/i_step_node.py”, line 142, in valid_args
self.node_params_serializer.is_valid(raise_exception=True)
File “/opt/maxkb/app/apps/application/flow/step_node/function_lib_node/i_function_lib_node.py”, line 32, in is_valid
f_lib = QuerySet(FunctionLib).filter(id=self.data.get(‘function_lib_id’)).first()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/models/query.py”, line 1057, in first
for obj in queryset[:1]:
File “/opt/py3/lib/python3.11/site-packages/django/db/models/query.py”, line 398, in iter
self._fetch_all()
File “/opt/py3/lib/python3.11/site-packages/django/db/models/query.py”, line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/models/query.py”, line 91, in iter
results = compiler.execute_sql(
^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/models/sql/compiler.py”, line 1560, in execute_sql
cursor = self.connection.cursor()
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 330, in cursor
return self._cursor()
^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 307, in _cursor
with self.wrap_database_errors:
File “/opt/py3/lib/python3.11/site-packages/django/db/utils.py”, line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 308, in _cursor
return self._prepare_cursor(self.create_cursor(name))
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/postgresql/base.py”, line 330, in create_cursor
cursor = self.connection.cursor()
^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.InterfaceError: connection already closed
Traceback (most recent call last):
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 308, in _cursor
return self._prepare_cursor(self.create_cursor(name))
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/opt/py3/lib/python3.11/site-packages/django/db/backends/postgresql/base.py”, line 330, in create_cursor
cursor = self.connection.cursor()
^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.InterfaceError: connection already closed
查看上述错误日志,结合搜索到的信息“Django 会自动管理数据库连接,但在某些异步或并发场景下,可能会遇到连接关闭的问题”
猜测应该是高级编排工作流,并发执行工作节点,导致和数据库连接出现问题,然后执行函数节点时,需要查询具体的函数节点code,此时就会报上述错误。
我把服务重启后,再执行调试就能正常运行,不过个人猜想,当服务并发量上去之后,还是会出现上述问题。
希望能在后续版本中优化解决上述性能所引起的问题!