Skip to content

[Context]: add graceful shutdown via InFlightTaskTracker #27

Description

@rian-be

Issue: Graceful Shutdown via InFlightTaskTracker

Summary

Enable graceful shutdown (e.g. Pod drain in Kubernetes) by tracking in-flight context tasks outside the core, subscribing to lifecycle events, and waiting for drain before exit.

Constraint / Decision

Core does not track active tasks (No Global Lock, no global registry per 9.2/10.4). Counting live in an external component (InFlightTaskTracker) in the hosting/adapter layer.

Flow

  1. Hosting (e.g. IHostedService) signals intention to stop.
  2. InFlightTaskTracker counts tasks by subscribing to ContextLifecycleEvent (Started / Completed).
  3. On stop signal, the host waits until the counter hits zero.
  4. Core ContextManager keeps working undisturbed during drain.

Scope

  • InFlightTaskTracker (hosting side) counting inflight via lifecycle events.
  • Integration sample with IHostedService drain + CancellationToken.
  • Guarantee: no load on ContextManager; no blocking.
  • Unit tests: count increments/decrements; drain completes.

Design Expectations

  • Tracking lives outside Core (adapter/hosting).
  • Uses lifecycle events already emitted (K9/K10) — no core changes.
  • Non-blocking to ContextManager.

Non-Goals

  • No policy/queue persistence.
  • No APM sink.

Metadata

Metadata

Assignees

No one assigned

    Labels

    adapterProtocol / transport integrationsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions