[Bug]: /healthz with a query string triggers a heartbeat

未關閉
#8,126 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@adityajai119 已經在處理了。

開始於 2026年11月13日。

  • #8127 來自 @adityajai119 —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
backend, testing

研究方向

Read the heartbeat middleware in src/node/routes/index.ts and the unit-test setup mentioned in the report. Reproduce with /healthz?probe=1 followed by /healthz and check the heartbeat state. Done means the query-string health check does not trigger a heartbeat, and a test covers that behavior; the author says they are opening a PR with a fix and test.

由索引模型根據 Issue 內容生成。

描述

Is there an existing issue for this?
  • I have searched the existing issues
OS/Web Information
  • Web Browser: not needed, reproduced with the unit tests
  • Local OS: Windows 11
  • Remote OS: Windows 11
  • Remote Architecture: x64
  • code-server --version: main at dda09f2
Steps to Reproduce
  1. Start code-server, for example with --auth none.
  2. Request /healthz with any query string, for example GET /healthz?probe=1, as a monitor or load balancer that adds a cache-busting or probe parameter does.
  3. Request /healthz again.
Expected

As the FAQ says, /healthz reports the status "without triggering a heartbeat", so an idle instance stays expired with lastHeartbeat: 0, the heartbeat file is not touched, and --idle-timeout-seconds still shuts it down.

Actual

Three requests in a row against an idle instance on main (dda09f2), from the unit test setup with --auth=none:

GET /healthz          -> {"status":"expired","lastHeartbeat":0}
GET /healthz?probe=1  -> {"status":"alive","lastHeartbeat":1794543674997}
GET /healthz          -> {"status":"alive","lastHeartbeat":1794543674997}

The middleware in src/node/routes/index.ts that skips the heartbeat for health checks matches the path against req.url, which includes the query string:

if (!/^\/healthz\/?$/.test(req.url)) {
  heart.beat()
}

So /healthz?probe=1 is treated as activity: it sets lastHeartbeat, touches the heartbeat file and cancels the idle shutdown timer. A monitor that polls with a query string more often than --idle-timeout-seconds keeps the instance from ever shutting down, and anything that watches the heartbeat file sees it as in use.

Logs

Not applicable.

Screenshot/Video

No response

Does this bug reproduce in native VS Code?

This cannot be tested in native VS Code

Does this bug reproduce in VS Code web?

This cannot be tested in VS Code web

Does this bug reproduce in GitHub Codespaces?

This cannot be tested in GitHub Codespaces

Are you accessing code-server over a secure context?
  • I am using a secure context.
Notes

The fix is to match req.path, which has no query string. I am opening a PR with the fix and a test.

AI-assisted: found and reproduced with an AI coding agent; the check above was run locally.

主要語言
TypeScript
星號
79.9k
分支
6.9k
平均合併
20 小時 21 分鐘
30 天內合併 PR
51

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

coder/code-server 的其他 Issue

查看 coder/code-server 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。