hhyo / Archery

SQL 审核查询平台
https://archerydms.com
Apache License 2.0
6.11k stars 1.69k forks source link

提交工单时报list index out of range #2051

Open uuzf opened 1 year ago

uuzf commented 1 year ago

重现步骤

提交工单时报list index out of range,查看日志发现在检查实例是否只读时数据连接异常:Can't connect to MySQL server on 'XXXXXXXXX',整个平台有40+MySQL实例,其他实例都正常只有这一个报错。

奇怪的是偶尔能提交成功,一次是直接使用粘贴的SQL执行就报错,将SQL改为手动输入就正常。第二次的情况是执行工单报错后直接使用《上线其他实例》按钮后就成功了。

每一个报错前面都有一个Can't connect to MySQL server的报错,可以确定的是数据库连接是没问题的,不管是从archery平台的服务器去手动连,还是在docker中手动连接都是正常的,在平台中SQL查询和实例管理模块都是连接正常。

预期外的结果

图片上传失败,我把日志贴出来。

日志文本

[2023-02-14 14:47:30,117][MainThread:140298777663296][task_id:default][mysql.py:164][WARNING]- MySQL语句执
行报错,语句:SELECT @@global.read_only;,错误信息Traceback (most recent call last):
  File "/opt/archery/sql/engines/mysql.py", line 146, in query
    conn = self.get_connection(db_name=db_name)
  File "/opt/archery/sql/engines/mysql.py", line 43, in get_connection
    self.conn = MySQLdb.connect(host=self.host, port=self.port, user=self.user, passwd=self.password,
  File "/opt/venv4archery/lib/python3.8/site-packages/MySQLdb/__init__.py", line 130, in Connect
    return Connection(*args, **kwargs)
  File "/opt/venv4archery/lib/python3.8/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'XXX.XXX.XXX.XXX' (110)")

[2023-02-14 14:47:30,587][MainThread:140298777663296][task_id:django-q][cluster.py:390][ERROR]- Failed [sqlreview-execute-1192] - list index out of range : Traceback (most recent call last):
  File "/opt/venv4archery/lib/python3.8/site-packages/django_q/cluster.py", line 436, in worker
    res = f(*task["args"], **task["kwargs"])
  File "/opt/archery/sql/utils/execute_sql.py", line 35, in execute
    return execute_engine.execute_workflow(workflow=workflow_detail)
  File "/opt/archery/sql/engines/mysql.py", line 292, in execute_workflow
    read_only = self.query(sql='SELECT @@global.read_only;').rows[0][0]
IndexError: list index out of range

版本

1.8.1

部署方式

Docker

是否还有其他可以辅助定位问题的信息?比如数据库版本等

No response

hhyo commented 1 year ago

这个主要是判断实例是否可写时获取状态异常了,看异常可以确认是和数据库连接有关,后续可以增加重试机制

uuzf commented 1 year ago

这个问题有临时的解决方案吗?