coze-dev / coze-dev/coze-studio

Elasticsearch 初始化脚本因 Windows 换行符(CRLF)执行失败,导致前端报 500 错误

Open
#2,725 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21.6k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

标题: [Bug] Elasticsearch 初始化脚本因 Windows 换行符(CRLF)执行失败,导致前端报 500 错误 (no such index)

环境信息:
- 操作系统: Windows (PowerShell)
- 部署方式: Docker Compose (docker-compose up -d)
- 镜像版本: cozedev/coze-studio-server:latest / bitnamilegacy/elasticsearch:8.18.0

Bug 描述:
在 Windows 主机上使用 Docker 部署 Coze Studio 时,Elasticsearch 的初始化脚本未能成功执行,导致必要的索引(如 project_draft)未被创建。当用户登录并访问主页或获取草稿列表时,后端报错 no such index [project_draft],前端接口 /api/intelligence_api/search/get_draft_intelligence_list 返回 HTTP 500 Internal Server Error。

复现步骤:
1. 在 Windows 系统上克隆仓库并运行 docker-compose up -d。
2. 等待所有容器启动完毕且状态为 healthy。
3. 登录 Coze Studio 前端页面。
4. 打开浏览器开发者工具的 Network 面板,发现 /api/intelligence_api/search/get_draft_intelligence_list 接口报 500 错误。

相关日志:

1. coze-server 日志 (docker logs coze-server):
[Serarch.DO] err : status: 404, failed: [index_not_found_exception], reason: no such index [project_draft]
[InternalError] error: status: 404, failed: [index_not_found_exception], reason: no such index [project_draft]
| http | localhost:8888 | 500 | ... | POST | /api/intelligence_api/search/get_draft_intelligence_list

2. coze-elasticsearch 日志 (docker logs coze-elasticsearch):
Running Elasticsearch initialization...
Adjusting: line 44: /setup_es_fixed.sh: cannot execute: required file not found
Elasticsearch initialization completed successfully!

根本原因分析:
经排查,容器内的 /setup_es_fixed.sh 脚本文件包含了 Windows 的换行符(CRLF \r\n)。当 Linux 容器尝试执行该脚本时,会将 \r 当作命令的一部分,从而报出 cannot execute: required file not found 错误。
由于该脚本执行失败,ES 内部的 project_draft 等索引未被创建,导致后端查询时报 404,最终转换为 500 报给前端。

临时解决方案:
进入 ES 容器,使用 sed 去除 \r 后手动执行该脚本,然后重启后端:
docker exec -it coze-elasticsearch sh -c "sed -i 's/\r//g' /setup_es_fixed.sh && sh /setup_es_fixed.sh"
docker restart coze-server

建议修复方案:
1. 在仓库根目录添加或更新 .gitattributes 文件,强制所有 shell 脚本使用 LF 换行符:
*.sh text eol=lf
2. 或者在构建 ES 镜像的 Dockerfile 中,在拷贝脚本后执行格式转换:
RUN sed -i 's/\r//g' /setup_es_fixed.sh 或 RUN apt-get install dos2unix && dos2unix /setup_es_fixed.sh
3. 考虑在初始化脚本执行失败时抛出明确的错误退出码(目前报错后依然打印了 Elasticsearch initialization completed successfully!,导致初始化逻辑被静默跳过)。

Contributor guide

Open the contributing guide

Research direction

Start by locating /setup_es_fixed.sh, the Elasticsearch image Dockerfile, and any root .gitattributes or docker-compose configuration that copies the script. Reproduce the Windows deployment and inspect the Elasticsearch container logs, then verify that initialization creates project_draft and that the draft-list endpoint no longer returns HTTP 500.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, elasticsearch, shell
Domain
databases, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.