From 8bb1ca0c01adb51e6adb6d02c12ced1f1e46b76e Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sun, 22 Nov 2026 15:59:48 -0800 Subject: [PATCH] fix(realtime): report liveness only on the public health probe GET /health is unauthenticated and publicly reachable, and returned this pod's live connection count. It now returns {"status":"ok"}. The connection counter had no other caller, so it is removed from the room manager. --- .../platform/self-hosting/observability.mdx | 2 +- apps/realtime/src/handlers/tables.test.ts | 1 - apps/realtime/src/handlers/workflow.test.ts | 1 - .../workspace-invalidation-room.test.ts | 1 - apps/realtime/src/rooms/redis-manager.ts | 5 ----- apps/realtime/src/rooms/types.ts | 3 --- apps/realtime/src/routes/http.test.ts | 10 +++++++++- apps/realtime/src/routes/http.ts | 19 +++---------------- 8 files changed, 13 insertions(+), 29 deletions(-) diff --git a/apps/docs/content/docs/platform/self-hosting/observability.mdx b/apps/docs/content/docs/platform/self-hosting/observability.mdx index 4878dcd22a3..753f777b2da 100644 --- a/apps/docs/content/docs/platform/self-hosting/observability.mdx +++ b/apps/docs/content/docs/platform/self-hosting/observability.mdx @@ -12,7 +12,7 @@ Use health checks, container logs, and infrastructure metrics to monitor your de | Service | Endpoint | Returns | |---|---|---| | app | `GET /api/health` | `{"status":"ok","timestamp":"..."}` | -| realtime | `GET /health` on port 3002 | `{"status":"ok","timestamp":"...","connections":0}` | +| realtime | `GET /health` on port 3002 | `{"status":"ok"}` | `/api/health` is a **liveness** signal only. It returns `200` as long as the process is serving HTTP — it does not check the database, Redis, or object storage. A healthy response does not mean the app can serve traffic successfully, so do not treat it as a dependency check. Verify dependencies with the [smoke test](/platform/self-hosting/verify) instead. diff --git a/apps/realtime/src/handlers/tables.test.ts b/apps/realtime/src/handlers/tables.test.ts index 48db7afc29d..706f717f09d 100644 --- a/apps/realtime/src/handlers/tables.test.ts +++ b/apps/realtime/src/handlers/tables.test.ts @@ -58,7 +58,6 @@ function createRoomManager(overrides?: Partial): IRoomManager { updateRoomLastModified: vi.fn().mockResolvedValue(undefined), emitToRoom: vi.fn(), getUniqueUserCount: vi.fn().mockResolvedValue(1), - getTotalActiveConnections: vi.fn().mockResolvedValue(0), shutdown: vi.fn().mockResolvedValue(undefined), initialize: vi.fn().mockResolvedValue(undefined), io: { diff --git a/apps/realtime/src/handlers/workflow.test.ts b/apps/realtime/src/handlers/workflow.test.ts index 20d92e37a6c..d3f4247f12f 100644 --- a/apps/realtime/src/handlers/workflow.test.ts +++ b/apps/realtime/src/handlers/workflow.test.ts @@ -76,7 +76,6 @@ function createRoomManager(overrides?: Partial): IRoomManager { updateRoomLastModified: vi.fn().mockResolvedValue(undefined), emitToRoom: vi.fn(), getUniqueUserCount: vi.fn().mockResolvedValue(1), - getTotalActiveConnections: vi.fn().mockResolvedValue(0), shutdown: vi.fn().mockResolvedValue(undefined), initialize: vi.fn().mockResolvedValue(undefined), io: { diff --git a/apps/realtime/src/handlers/workspace-invalidation-room.test.ts b/apps/realtime/src/handlers/workspace-invalidation-room.test.ts index 7f8f6cd8fba..4647f6c3872 100644 --- a/apps/realtime/src/handlers/workspace-invalidation-room.test.ts +++ b/apps/realtime/src/handlers/workspace-invalidation-room.test.ts @@ -64,7 +64,6 @@ function createRoomManager(overrides?: Partial): IRoomManager { updateRoomLastModified: vi.fn().mockResolvedValue(undefined), emitToRoom: vi.fn(), getUniqueUserCount: vi.fn().mockResolvedValue(1), - getTotalActiveConnections: vi.fn().mockResolvedValue(0), shutdown: vi.fn().mockResolvedValue(undefined), initialize: vi.fn().mockResolvedValue(undefined), io: { diff --git a/apps/realtime/src/rooms/redis-manager.ts b/apps/realtime/src/rooms/redis-manager.ts index 17d67377531..97e32c1106b 100644 --- a/apps/realtime/src/rooms/redis-manager.ts +++ b/apps/realtime/src/rooms/redis-manager.ts @@ -457,9 +457,4 @@ export class RedisRoomManager implements IRoomManager { const users = await this.getRoomUsers(room) return new Set(users.map((u) => u.userId)).size } - - async getTotalActiveConnections(): Promise { - // Local instance only; the true cross-pod count would require aggregation. - return this._io.sockets.sockets.size - } } diff --git a/apps/realtime/src/rooms/types.ts b/apps/realtime/src/rooms/types.ts index 561577eefc5..8384cdd7490 100644 --- a/apps/realtime/src/rooms/types.ts +++ b/apps/realtime/src/rooms/types.ts @@ -125,7 +125,4 @@ export interface IRoomManager { /** Number of unique users in a room. */ getUniqueUserCount(room: RoomRef): Promise - - /** Total active connections tracked by this instance. */ - getTotalActiveConnections(): Promise } diff --git a/apps/realtime/src/routes/http.test.ts b/apps/realtime/src/routes/http.test.ts index c4a59953c37..e8fe9dcd914 100644 --- a/apps/realtime/src/routes/http.test.ts +++ b/apps/realtime/src/routes/http.test.ts @@ -21,7 +21,6 @@ function createMocks(req: Partial) { const to = vi.fn(() => ({ emit })) const roomManager = { io: { to }, - getTotalActiveConnections: vi.fn().mockResolvedValue(0), isReady: vi.fn().mockReturnValue(true), emitToRoom: vi.fn(), } as unknown as IRoomManager @@ -55,6 +54,15 @@ function requestWithBody(url: string, body: unknown): Partial { } describe('createHttpHandler', () => { + it('answers the public health probe with liveness only', async () => { + const { handler, req, res, writeHead, end } = createMocks({ method: 'GET', url: '/health' }) + + await handler(req, res) + + expect(writeHead).toHaveBeenCalledWith(200, { 'Content-Type': 'application/json' }) + expect(JSON.parse(end.mock.calls[0][0])).toEqual({ status: 'ok' }) + }) + it('invalidates the shared generation before notifying every open editor', async () => { mockInvalidateDocument.mockResolvedValueOnce({ status: 'applied', docId: 'old-document' }) const { handler, req, res, writeHead, to, emit } = createMocks( diff --git a/apps/realtime/src/routes/http.ts b/apps/realtime/src/routes/http.ts index cf0c9f74d12..152e8793e4e 100644 --- a/apps/realtime/src/routes/http.ts +++ b/apps/realtime/src/routes/http.ts @@ -84,23 +84,10 @@ export function createHttpHandler(roomManager: IRoomManager, logger: Logger) { return async (req: IncomingMessage, res: ServerResponse) => { res.setHeader('X-Robots-Tag', 'noindex, nofollow') - // Health check doesn't require auth + // Unauthenticated and publicly reachable, so it reports liveness only. if (req.method === 'GET' && req.url === '/health') { - try { - const connections = await roomManager.getTotalActiveConnections() - res.writeHead(200, { 'Content-Type': 'application/json' }) - res.end( - JSON.stringify({ - status: 'ok', - timestamp: new Date().toISOString(), - connections, - }) - ) - } catch (error) { - logger.error('Error in health check:', error) - res.writeHead(503, { 'Content-Type': 'application/json' }) - res.end(JSON.stringify({ status: 'error', message: 'Health check failed' })) - } + res.writeHead(200, { 'Content-Type': 'application/json' }) + res.end(JSON.stringify({ status: 'ok' })) return }