Repository navigation
Description
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.rswrapper to return the unspawned runner. - Move only
peers_inactivity_updatefromJobManager::legacy_jobsto a direct, namedJobManager::spawncomponent. - Preserve the
tracker_usage_statisticsgate, the hardcoded 15s interval, the immediate first tick, the metrics update logic, and the weak-pointer lifetime behavior. - Remove the
signalfeature from the package'stokiodependency 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_cleanupremains the only legacy registration). - Shared server lifecycle API,
Haltedbridge, drain policies (SI-2, SI-10+), and process deadline/exit-code policy (SI-20).
Acceptance Criteria
- AC1:
activity_metrics_updater.rsin theswarm-coordination-registrypackage contains notokio::signal::ctrl_c()call. - AC2: The updater accepts an injected
CancellationTokenand returnsCompletion::Cancelledafter cancellation. - AC3: Weak-pointer expiry of the registry or statistics repository returns
Completion::Completed. - AC4: With
tracker_usage_statistics = true,src/app.rsregisters one named directJoinSetcomponent,peers_inactivity_update, rather than a legacy handle. - AC5:
JobManager::cancel()produces the namedpeers_inactivity_update: JobStatus::Cancelledoutcome 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_cleanupremains the onlyregister_legacyregistration and is not changed by this task. -
linter allexits with code0; relevant tests pass; manual verification recorded in the issue-localmanual-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).
Activity
fix(review): cover independent activity updater expiry
docs(issues): add issue specification for #2221
Merge torrust#2224: feat(shutdown): [torrust#2221] migrate activity m…
feat(shutdown): migrate activity metrics updater to cancellation token
chore(issues): archive closed issue torrust#2221 spec to docs/issues/…
Merge #2227: chore(issues): archive closed issue #2221 spec to docs/i…