Skip to content

[service] Processes do not exit after a drain, and nothing closes KV or Prisma #2630

Closed

Description

@rickylabs

Summary

After a completed or timed-out drain, background children and services return from their entry point but never end the process. No role closes its KV, Prisma or Redis handles, so whether the process exits depends on which handles happen to stay open.

Evidence (main at b0eb079, same on v0.0.9)

  • packages/plugin/src/presentation/run-child-health-process.ts:131-143: on a stop signal it awaits completion, removes the signal listeners, shuts the health server down and returns. Only the fatal path throws. The comment on line 141 already says "Bootstrap may leave dependency handles alive".
  • packages/service/src/builder/service-listener.ts and service-shutdown.ts: the 30 s drain timeout (DEFAULT_DRAIN_TIMEOUT_MS) returns { timedOut: true } and logs a warning. Nothing forces an exit.
  • closeKv() (packages/kv/application/shared.ts:187) has no runtime caller outside the KV package. Prisma is disconnected only for the health-check client in defineService. The workers child opens KV in plugins/workers/bin/runtime.ts and never closes it.
  • The only Deno.exit in runtime code is the opt-in OTel SDK provider (packages/telemetry/src/adapters/otel/otel-sdk.ts), which can exit 0 before the drain ends.

Not verified by running: which handle keeps the event loop alive in practice.

Expected behavior

After a drain, each role closes the handles it opened (KV, Prisma, Redis connections) and the process ends with a defined exit code: 0 for a clean drain, non-zero for a timed-out drain or a fatal child.

Acceptance

  • A background child started through runChildHealthProcess exits on SIGTERM within its drain budget, proven by a subprocess test that fails on current main.
  • A service started through serve() exits after a completed drain and after a timed-out drain, with distinct exit codes, proven by a subprocess test.
  • Each role closes the KV, Prisma and Redis handles it opened before it exits.
  • The exit codes are documented.

Acceptance verified by #2641 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions