Skip to content

Commit ffda23f

Browse files
authored
fix(realtime): report liveness only on the public health probe (#10324)
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.
1 parent 1ad379f commit ffda23f

8 files changed

Lines changed: 13 additions & 29 deletions

File tree

‎apps/docs/content/docs/platform/self-hosting/observability.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Use health checks, container logs, and infrastructure metrics to monitor your de
1212
| Service | Endpoint | Returns |
1313
|---|---|---|
1414
| app | `GET /api/health` | `{"status":"ok","timestamp":"..."}` |
15-
| realtime | `GET /health` on port 3002 | `{"status":"ok","timestamp":"...","connections":0}` |
15+
| realtime | `GET /health` on port 3002 | `{"status":"ok"}` |
1616

1717
<Callout type="warn">
1818
`/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.

‎apps/realtime/src/handlers/tables.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function createRoomManager(overrides?: Partial<IRoomManager>): IRoomManager {
5858
updateRoomLastModified: vi.fn().mockResolvedValue(undefined),
5959
emitToRoom: vi.fn(),
6060
getUniqueUserCount: vi.fn().mockResolvedValue(1),
61-
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
6261
shutdown: vi.fn().mockResolvedValue(undefined),
6362
initialize: vi.fn().mockResolvedValue(undefined),
6463
io: {

‎apps/realtime/src/handlers/workflow.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ function createRoomManager(overrides?: Partial<IRoomManager>): IRoomManager {
7676
updateRoomLastModified: vi.fn().mockResolvedValue(undefined),
7777
emitToRoom: vi.fn(),
7878
getUniqueUserCount: vi.fn().mockResolvedValue(1),
79-
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
8079
shutdown: vi.fn().mockResolvedValue(undefined),
8180
initialize: vi.fn().mockResolvedValue(undefined),
8281
io: {

‎apps/realtime/src/handlers/workspace-invalidation-room.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ function createRoomManager(overrides?: Partial<IRoomManager>): IRoomManager {
6464
updateRoomLastModified: vi.fn().mockResolvedValue(undefined),
6565
emitToRoom: vi.fn(),
6666
getUniqueUserCount: vi.fn().mockResolvedValue(1),
67-
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
6867
shutdown: vi.fn().mockResolvedValue(undefined),
6968
initialize: vi.fn().mockResolvedValue(undefined),
7069
io: {

‎apps/realtime/src/rooms/redis-manager.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,4 @@ export class RedisRoomManager implements IRoomManager {
457457
const users = await this.getRoomUsers(room)
458458
return new Set(users.map((u) => u.userId)).size
459459
}
460-
461-
async getTotalActiveConnections(): Promise<number> {
462-
// Local instance only; the true cross-pod count would require aggregation.
463-
return this._io.sockets.sockets.size
464-
}
465460
}

‎apps/realtime/src/rooms/types.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,4 @@ export interface IRoomManager {
125125

126126
/** Number of unique users in a room. */
127127
getUniqueUserCount(room: RoomRef): Promise<number>
128-
129-
/** Total active connections tracked by this instance. */
130-
getTotalActiveConnections(): Promise<number>
131128
}

‎apps/realtime/src/routes/http.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function createMocks(req: Partial<IncomingMessage>) {
2121
const to = vi.fn(() => ({ emit }))
2222
const roomManager = {
2323
io: { to },
24-
getTotalActiveConnections: vi.fn().mockResolvedValue(0),
2524
isReady: vi.fn().mockReturnValue(true),
2625
emitToRoom: vi.fn(),
2726
} as unknown as IRoomManager
@@ -55,6 +54,15 @@ function requestWithBody(url: string, body: unknown): Partial<IncomingMessage> {
5554
}
5655

5756
describe('createHttpHandler', () => {
57+
it('answers the public health probe with liveness only', async () => {
58+
const { handler, req, res, writeHead, end } = createMocks({ method: 'GET', url: '/health' })
59+
60+
await handler(req, res)
61+
62+
expect(writeHead).toHaveBeenCalledWith(200, { 'Content-Type': 'application/json' })
63+
expect(JSON.parse(end.mock.calls[0][0])).toEqual({ status: 'ok' })
64+
})
65+
5866
it('invalidates the shared generation before notifying every open editor', async () => {
5967
mockInvalidateDocument.mockResolvedValueOnce({ status: 'applied', docId: 'old-document' })
6068
const { handler, req, res, writeHead, to, emit } = createMocks(

‎apps/realtime/src/routes/http.ts‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,10 @@ export function createHttpHandler(roomManager: IRoomManager, logger: Logger) {
8484
return async (req: IncomingMessage, res: ServerResponse) => {
8585
res.setHeader('X-Robots-Tag', 'noindex, nofollow')
8686

87-
// Health check doesn't require auth
87+
// Unauthenticated and publicly reachable, so it reports liveness only.
8888
if (req.method === 'GET' && req.url === '/health') {
89-
try {
90-
const connections = await roomManager.getTotalActiveConnections()
91-
res.writeHead(200, { 'Content-Type': 'application/json' })
92-
res.end(
93-
JSON.stringify({
94-
status: 'ok',
95-
timestamp: new Date().toISOString(),
96-
connections,
97-
})
98-
)
99-
} catch (error) {
100-
logger.error('Error in health check:', error)
101-
res.writeHead(503, { 'Content-Type': 'application/json' })
102-
res.end(JSON.stringify({ status: 'error', message: 'Health check failed' }))
103-
}
89+
res.writeHead(200, { 'Content-Type': 'application/json' })
90+
res.end(JSON.stringify({ status: 'ok' }))
10491
return
10592
}
10693

0 commit comments

Comments
 (0)