Skip to content

Migrate activity metrics updater to CancellationToken #2221

Closed

Description

@josecelano

Parent EPIC: #1488 — Overhaul: Tracker Shutdown (roadmap sequence 4, draft SI-5).

Goal

Make the peers activity metrics updater (peers_inactivity_update) a directly supervised, token-aware top-level component. It must respond to JobManager::cancel() without subscribing to an OS signal, report its explicit normal terminal state, and leave no updater task detached.

Background

The #1588 task inventory confirms peers_inactivity_update is one of the pre-spawned periodic jobs still retained in JobManager::legacy_jobs. Its loop in packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs waits on tokio::signal::ctrl_c(), ignores the manager's root cancellation token, and is therefore deliberately aborted after the shared ten-second deadline during a SIGTERM shutdown. The #2169 SIGTERM evidence explicitly left this job outside its claim.

#1586 established that direct top-level components must be passed as futures to JobManager::spawn; adding a token while retaining start_job() -> JoinHandle<()> would not complete the migration. #2169 (SI-4) migrated torrent cleanup with the target shape: run_job(..., CancellationToken) -> impl Future<Output = Completion>, adapted in src/app.rs through component_runner. This task applies the same reviewed pattern to the second periodic job.

Scope

In scope:

  • Replace the pre-spawned updater starter with an unspawned, token-aware runner returning torrust_tracker_events::shutdown::Completion.
  • Update the src/bootstrap/jobs/activity_metrics_updater.rs wrapper to return the unspawned runner.
  • Move only peers_inactivity_update from JobManager::legacy_jobs to a direct, named JobManager::spawn component.
  • Preserve the tracker_usage_statistics gate, the hardcoded 15s interval, the immediate first tick, the metrics update logic, and the weak-pointer lifetime behavior.
  • Remove the signal feature from the package's tokio dependency if nothing else in the package uses it.
  • Deterministic lifecycle tests: injected-token cancellation, weak-pointer expiry, and named manager outcome.
  • Direct-binary SIGTERM evidence and evidence that metrics are still updated during normal operation.

Out of scope:

  • Making the 15s interval configurable.
  • Fixing the startup-time inactivity cutoff computation (pre-existing bug; separate follow-up issue after this merges).
  • UDP IP-ban cleanup lifecycle (udp_ban_cleanup remains the only legacy registration).
  • Shared server lifecycle API, Halted bridge, drain policies (SI-2, SI-10+), and process deadline/exit-code policy (SI-20).

Acceptance Criteria

  • AC1: activity_metrics_updater.rs in the swarm-coordination-registry package contains no tokio::signal::ctrl_c() call.
  • AC2: The updater accepts an injected CancellationToken and returns Completion::Cancelled after cancellation.
  • AC3: Weak-pointer expiry of the registry or statistics repository returns Completion::Completed.
  • AC4: With tracker_usage_statistics = true, src/app.rs registers one named direct JoinSet component, peers_inactivity_update, rather than a legacy handle.
  • AC5: JobManager::cancel() produces the named peers_inactivity_update: JobStatus::Cancelled outcome without an OS signal.
  • AC6: Direct-binary SIGTERM evidence shows the updater's cancellation log and cooperative manager outcome, not its deadline-abort outcome.
  • AC7: Activity metrics are still updated during normal operation across at least two intervals.
  • AC8: udp_ban_cleanup remains the only register_legacy registration and is not changed by this task.
  • linter all exits with code 0; relevant tests pass; manual verification recorded in the issue-local manual-verification-evidence.md.

Specification

Full specification (design and ownership review, implementation plan, commit points, verification plan, risks): docs/issues/open/<number>-1488-si-5-migrate-activity-metrics-updater/ISSUE.md (in develop after the implementation PR merges).

Related: #1586, #1588, #2132, #2169.

Activity

  1. self-assigned this
    on Sep 15, 2026
  2. added a commit that references this issue on Sep 15, 2026
  3. added a commit that references this issue on Sep 15, 2026
    674e72c
  4. added 2 commits that reference this issue on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions