diff --git a/Dockerfile b/Dockerfile index 74c0883..6f98e2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN npm ci \ FROM node:lts-alpine AS runner -RUN apk --no-cache add curl \ +RUN apk --no-cache add curl tini \ && mkdir /app && chown node:node /app USER node @@ -26,4 +26,7 @@ ARG PACKAGE_VERSION ENV APP_VERSION=${PACKAGE_VERSION} ENV NODE_ENV=production +# tini as PID 1 reaps orphaned healthcheck processes, which node does not (GitHub #66). +# -s keeps reaping, without a warning, when PID 1 is already an init (compose `init: true`). +ENTRYPOINT ["/sbin/tini", "-s", "--"] CMD ["node", "dist/index.js" ] diff --git a/app/package.json b/app/package.json index 6d43690..d5a4fd1 100644 --- a/app/package.json +++ b/app/package.json @@ -8,7 +8,7 @@ "build:client": "tsc -p tsconfig.client.json", "test": "vitest run", "test:watch": "vitest", - "test:container": "podman build --build-arg PACKAGE_VERSION=$(npm pkg get version | xargs) --format docker -t immich-proxy-test .. && podman run --init -it -p=3000:3000 --env-file .env --restart=always immich-proxy-test", + "test:container": "podman build --build-arg PACKAGE_VERSION=$(npm pkg get version | xargs) --format docker -t immich-proxy-test .. && podman run -it -p=3000:3000 --env-file .env --restart=always immich-proxy-test", "start": "node dist/index.js" }, "author": "Alan Grainger", diff --git a/app/src/immich.ts b/app/src/immich.ts index 2e0012c..ab8a0c2 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -622,9 +622,14 @@ export function isKey (key: string) { /** * Reachability ping for the `/share/healthcheck` route. + * + * Capped at 3 s so a slow Immich fails the healthcheck instead of hanging it. + * The compose healthcheck gives curl 4 s inside Docker's 5 s timeout; a check + * that overruns gets killed and leaves a zombie curl behind (GitHub #66). */ export async function accessible () { - return !!(await request('/server/ping')) + // The catch covers a timeout during the body read, which request() does not + return !!(await request('/server/ping', { signal: AbortSignal.timeout(3000) }).catch(() => null)) } // Minimum Immich server version IPP is compatible with diff --git a/docker-compose.yml b/docker-compose.yml index 03f38c7..4d22016 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,6 @@ services: PUBLIC_BASE_URL: https://your-proxy-url.com IMMICH_URL: http://your-internal-immich-server:2283 healthcheck: - test: curl -s http://localhost:3000/share/healthcheck -o /dev/null || exit 1 + test: curl -sf -m 4 http://localhost:3000/share/healthcheck -o /dev/null || exit 1 start_period: 10s timeout: 5s