trilium/apps/server/scripts
Elian Doran bb9c5f6378
fix(healthcheck): end the probe at its deadline, and stop loading the server
Two defects in the docker healthcheck, in one module because the second
rewrote the file the first touches.

The probe passed `timeout: 2000` to http.request, which only arms the
socket idle timer and emits a "timeout" event. Nothing listened for it
and nothing destroyed the request, so the option never had any effect:
against a server that completes the TCP handshake and then goes quiet,
the probe waited without end. That is the exact failure a healthcheck
exists to catch, and it was the one case the probe could not report.
Docker's own 30 s --timeout, which no Dockerfile overrides, was all that
ended these attempts, each of them pinning a node process for the full
30 s first. Handle the event: log the deadline, destroy the request,
report unhealthy.

The bundle was 3 MB because docker_healthcheck.ts imported config.ts,
which reaches @triliumnext/core for envToBoolean and stringToInt.
That import is a namespace re-export, so the namespace object keeps
every export of utils/index.ts live, and with it sanitize-html, cheerio,
parse5, domino, mime-db and iconv-lite. Weight was not the whole
problem: loading that chain also created the data directory, wrote a
config sample when none existed, and ran the process.exit(1) in
resource_dir.ts, so the verdict depended on filesystem layout rather
than on the server. No bundler setting removes that. Marking both
packages sideEffects-free still left 5.36 MB, because the chain is
genuinely reachable and genuinely side-effectful.

resolveHealthcheckTarget() reads the same environment variables and the
same [Network] section of config.ini instead, read-only, importing
nothing. Measured against the built artifact:

  bundle    3002 KB  ->  5.3 KB
  cpu        154 ms  ->  ~30 ms per probe (bare node is ~27 ms)
  data dir   created ->  untouched

Behavior is unchanged across 200, 500, unix socket, refused connection
and https=true; the silent server now exits 1 after 2032 ms.

Duplicating the resolution is the cost, so the tests load config.ts,
port.ts and host.ts over six environments and assert both readings
agree, rather than checking hand-written expectations. build.ts fails
the build past 100 KB, verified by lowering the limit until it fired;
that guard runs on every image build, unlike spec/build-checks, which
no workflow invokes.

healthcheck.ts is at 100% lines, branches and functions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 16:02:22 +03:00
..
build-server.sh chore(server): fix dist creation 2026-04-09 22:31:50 +03:00
build.ts fix(healthcheck): end the probe at its deadline, and stop loading the server 2026-08-23 16:02:22 +03:00
export-schema.sh chore(regroup): adapt export-schema script 2025-12-06 10:29:08 +02:00
generate_document.ts feat(server): remove cls wrapper 2026-05-27 21:34:14 +03:00
generate-cert.sh chore(regroup): clean bin dir 2025-12-06 10:50:42 +02:00