From 34bfa71bd562827a83130239bd5b2a4417c68586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Thu, 21 May 2026 09:27:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(update):=20=E4=BF=AE=E5=A4=8D=20WebSocket?= =?UTF-8?q?=20101=20=E8=AF=AF=E5=88=A4=20+=20=E6=B8=85=E7=90=86=E5=AD=A4?= =?UTF-8?q?=E5=84=BF=E5=AE=B9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - WebSocket 探测:curl 在 101 握手后无法继续 WS 协议会追加 000, 返回值为 "101000",改为 grep '^101' 判断首三位而非精确匹配 - up -d 加 --remove-orphans:自动清理已从 compose 文件移除的容器 (如之前删除的 ops-web),消除每次升级的 WARN 噪音 Co-Authored-By: Claude Sonnet 4.6 --- VERSION | 2 +- scripts/update.sh | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 2ac736a..10b798a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2026.05.20-private.6 +2026.05.21-private.1 diff --git a/scripts/update.sh b/scripts/update.sh index 28c6345..67e56fa 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -448,11 +448,11 @@ _COMPOSE="docker compose --env-file ${ROOT_DIR}/.env \ # 使用 up -d 而非 restart:restart 只重启容器进程,不会切换到新拉取的镜像; # up -d 会检测镜像变更并重建容器,是应用新版本的正确方式。 info "应用新镜像并重启 tenant-service ..." -$_COMPOSE up -d --no-deps tenant-service +$_COMPOSE up -d --no-deps --remove-orphans tenant-service ok "tenant-service 已更新" info "应用新镜像并重启 nginx ..." -$_COMPOSE up -d --no-deps nginx +$_COMPOSE up -d --no-deps --remove-orphans nginx ok "nginx 已更新" # --------------------------------------------------------------------------- @@ -513,7 +513,13 @@ _ws_probe="$(curl -sk --noproxy '*' --max-time 5 \ -H "Sec-WebSocket-Version: 13" \ "http://127.0.0.1:${_NGINX_PORT}/ws/im" 2>/dev/null || echo 000)" -if [ "$_ws_probe" = "101" ]; then +# curl 对 WebSocket 握手的处理:服务端回 101 后 curl 不会说 WS 协议, +# 连接立刻断开,-w '%{http_code}' 可能输出 "101" 或 "101000"(101 + 后续 000)。 +# 只要首三位是 101 即代表握手成功。 +_ws_ok=0 +printf '%s' "$_ws_probe" | grep -q '^101' && _ws_ok=1 + +if [ "$_ws_ok" -eq 1 ]; then ok "容器 nginx → im-service WebSocket 握手正常 (HTTP 101)" # 进一步探测外部域名(需要上层 TLS 代理正确透传 Upgrade 头) if [ -n "$_CONSOLE_DOMAIN" ]; then @@ -525,7 +531,7 @@ if [ "$_ws_probe" = "101" ]; then -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \ -H "Sec-WebSocket-Version: 13" \ "${_ext_ws_url}" 2>/dev/null || echo 000)" - if [ "$_ext_code" = "101" ]; then + if printf '%s' "$_ext_code" | grep -q '^101'; then ok "外部域名 WebSocket 握手正常 (HTTP 101) → ${_SDK_IM_WS_URL}" else warn "外部域名 WebSocket 握手失败 (HTTP ${_ext_code}) → ${_SDK_IM_WS_URL}"