Skip to content

[Feature] Graceful-shutdown wiring: HTTP unbind + cluster leave via CoordinatedShutdown + runUntilTerminated() #549

Description

@pathosDev

Use case

Every HTTP/cluster example hand-rolls the same shutdown choreography: process.on('SIGINT', ...) -> server.unbind() -> cluster.leave() -> system.terminate() — even though CoordinatedShutdown exists with phase-ordered shutdown. Users copy this boilerplate into production apps, usually getting the ordering or double-signal handling subtly wrong.

Proposed API

const server = await system.http(port).bind(routes);   // registers unbind in the service-unbind phase automatically
await system.runUntilTerminated();                     // installs SIGINT/SIGTERM handlers -> CoordinatedShutdown.run()
  • HTTP bind and broker actors register their teardown in the appropriate CoordinatedShutdown phase on creation (opt-out via options).
  • runUntilTerminated() (name open) resolves when the system has fully terminated; signal handlers are removed afterwards.
  • Cross-runtime: signal handling goes through src/runtime/ (Bun/Node/Deno differences).

Acceptance criteria

  • One-line graceful shutdown in every example; hand-rolled SIGINT choreography deleted
  • Unbind/leave/terminate ordering guaranteed by CoordinatedShutdown phases
  • Works on Bun, Node, Deno (smoke case)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: mediumUseful, not urgentproduction-goalBlocks or defines the path to production readiness

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions