Bug: Docker healthcheck always reports healthy (process.exit never called) #121

Closed
opened 2026-05-17 21:27:01 -05:00 by null · 0 comments
Owner

Problem

The Dockerfile HEALTHCHECK CMD uses:

node -e "fetch(http://localhost:3001/api/health).then(r => r.ok ? 0 : 1).catch(() => 1)" || exit 1

The .then(r => r.ok ? 0 : 1) returns a value inside the Promise chain, but node -e exits with code 0 after the expression evaluates. The resolved Promise value does not set the process exit code. The || exit 1 only catches if node itself crashes, not if the health check fails.

Result: the health check ALWAYS reports healthy, even if the Express server is down or returning 500 errors.

Fix

Use process.exit() inside the then/catch:

node -e "fetch(http://localhost:3001/api/health).then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"

This ensures the node process exits with the correct code.

Files

  • Dockerfile — HEALTHCHECK line

Severity

Medium — Docker will never detect an unhealthy container

## Problem The Dockerfile HEALTHCHECK CMD uses: ``` node -e "fetch(http://localhost:3001/api/health).then(r => r.ok ? 0 : 1).catch(() => 1)" || exit 1 ``` The `.then(r => r.ok ? 0 : 1)` returns a value inside the Promise chain, but `node -e` exits with code 0 after the expression evaluates. The resolved Promise value does not set the process exit code. The `|| exit 1` only catches if `node` itself crashes, not if the health check fails. Result: the health check ALWAYS reports healthy, even if the Express server is down or returning 500 errors. ## Fix Use `process.exit()` inside the then/catch: ``` node -e "fetch(http://localhost:3001/api/health).then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" ``` This ensures the node process exits with the correct code. ## Files - Dockerfile — HEALTHCHECK line ## Severity Medium — Docker will never detect an unhealthy container
null closed this issue 2026-05-17 21:35:15 -05:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: null/Queue-North-Website#121
No description provided.