-
Notifications
You must be signed in to change notification settings - Fork 409
Open
Labels
bugSomething isn't workingSomething isn't working
Description
SQLBot Version
main
Bug 1: /dashboard/load_resource SQL 语法错误
- 位置:
backend/apps/dashboard/crud/dashboard_service.py:40 - 触发方式: 访问
/api/dashboard/load_resource - 问题描述: SQL 将
updator.id转为字符时写成id:: varchar,PostgreSQL 不接受::与类型名之间的空格,执行立即报syntax error at or near "varchar"。 - 影响: 仪表盘详情无法加载,接口直接返回 500。
- 修复建议: 改为
updator.id::varchar或CAST(updator.id AS varchar)。
JMeter 复现步骤
- 新建测试计划 → 线程组,线程数 1,循环 1。
- 线程组下添加 HTTP Request:
- Method:
POST - Path:
/api/dashboard/load_resource - Server Name、Port 根据部署填写。
- Method:
- Body Data 填入
{"id": "<现有仪表盘ID>"},并在 HTTP Header Manager 中添加Content-Type: application/json以及有效Authorization。 - 运行测试,响应码 500,Body 出现
syntax error at or near "varchar"即可复现。
Bug 2: LLMService 复用全局 Session 线程不安全
- 位置:
backend/apps/chat/task/llm.py:60 - 触发方式: 任一流式接口(如
/api/chat/question、/api/chat/recommend_questions/{id})在并发场景下调用。 - 问题描述: 模块级别创建了全局
db_session = session_maker(),FastAPI 将任务提交到ThreadPoolExecutor(max_workers=200)。SQLAlchemySession不是线程安全对象,并发读写会抛出sqlalchemy.exc.InvalidRequestError或导致事务异常。 - 影响: 多用户同时提问时随机返回 500,或出现错乱数据。
- 修复建议: 每次实例化
LLMService时创建独立 Session(或注入 FastAPI 的会话依赖),任务完成后关闭/回收。
JMeter 并发复现步骤
前置: 调用 /api/chat/start 创建对话,记录返回的 chat_id 与有效的 Authorization。
- 线程组配置:
- 线程数 20
- Ramp-Up 5 秒
- 循环次数 5
- 添加 HTTP Request:
- Method:
POST - Path:
/api/chat/question - Body Data 示例:
{ "chat_id": <chat_id>, "question": "帮我分析表 orders 的数据", "datasource": <已有数据源ID> }
- Method:
- Header Manager 添加:
Content-Type: application/jsonAuthorization: Bearer <token>
- 运行压测,部分请求会返回 500,响应体或日志中出现
InvalidRequestError,This Session's transaction has been closed等 Session 相关错误,即证明 Bug 2 被触发。
Bug 3: 删除会话接口使用 GET 造成破坏性请求
- 位置:
backend/apps/chat/api/chat.py:72 - 触发方式: 浏览器或任何客户端发送
GET /api/chat/delete/{chart_id}。 - 问题描述: GET 应为幂等读操作,该接口却直接删除资源,容易被恶意网页通过
<img src>等方式触发,存在 CSRF 与误删风险。 - 影响: 登录用户只要访问恶意页面就可能丢失历史会话。
- 修复建议: 改为
DELETE /api/chat/{chart_id},并结合 CSRF/鉴权头校验。
JMeter 复现步骤
前置: 先调用 /api/chat/start 创建会话,得到 chart_id。
- 新建线程组,线程数 1。
- HTTP Request 配置:
- Method:
GET - Path:
/api/chat/delete/<chart_id> - Header Manager 添加有效的
Authorization。
- Method:
- 运行测试,请求返回 200/204(具体取决于实现)。随后再调用
/api/chat/get/<chart_id>会返回 404 或 500,说明会话已被删除,证实 GET 请求具有破坏性。
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working