From 5393d75573efdbd1659bbacf43e280325173e8b1 Mon Sep 17 00:00:00 2001 From: adityajai119 Date: Fri, 13 Nov 2026 10:11:23 +0530 Subject: [PATCH] Skip the heartbeat for /healthz requests with a query string Fixes #8126 --- src/node/routes/index.ts | 2 +- test/unit/node/routes/health.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index ec2e3af0573d..ece235beec22 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -66,7 +66,7 @@ export const register = async ( const common: express.RequestHandler = (req, _, next) => { // /healthz|/healthz/ needs to be excluded otherwise health checks will make // it look like code-server is always in use. - if (!/^\/healthz\/?$/.test(req.url)) { + if (!/^\/healthz\/?$/.test(req.path)) { // NOTE@jsjoeio - intentionally not awaiting the .beat() call here because // we don't want to slow down the request. heart.beat() diff --git a/test/unit/node/routes/health.test.ts b/test/unit/node/routes/health.test.ts index 5f56b4a1ffac..456527192b24 100644 --- a/test/unit/node/routes/health.test.ts +++ b/test/unit/node/routes/health.test.ts @@ -19,6 +19,14 @@ describe("health", () => { expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" }) }) + it("/healthz with a query string", async () => { + codeServer = await integration.setup(["--auth=none"], "") + const resp = await codeServer.fetch("/healthz", undefined, { probe: "1" }) + expect(resp.status).toBe(200) + const json = await resp.json() + expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" }) + }) + it("/healthz (websocket)", async () => { codeServer = await integration.setup(["--auth=none"], "") const ws = codeServer.ws("/healthz")