Skip to content

Migrate torrent cleanup to CancellationToken #2169

Closed

Description

@josecelano

Goal

Make torrent cleanup 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 cleanup task detached.

Scope

  • Replace the pre-spawned torrent-cleanup starter with an unspawned, token-aware runner.
  • Move only torrent_cleanup from JobManager::legacy_jobs to direct named JobManager::spawn ownership.
  • Preserve the cleanup configuration gate, interval behavior, cleanup logic, and weak TorrentsManager lifetime behavior.
  • Add deterministic cancellation and direct-supervisor-ownership tests.
  • Verify both direct-binary SIGTERM cancellation and real inactive-peer cleanup through the REST API.
  • After the functional verification, add the reusable manual cleanup verification skill in a separate documentation commit.

Out of Scope

  • peers_inactivity_update migration (SI-5).
  • UDP IP-ban cleanup lifecycle changes.
  • Cleanup policy or interval configuration changes.
  • Server lifecycle APIs, drain policies, process deadline, and exit-code policy.

Key Constraints

The runner must be passed directly to JobManager::spawn; retaining a pre-spawned JoinHandle would require the wrapper pattern that #1586 prohibits. The runner returns generic Completion: token cancellation returns Cancelled; weak TorrentsManager expiry returns Completed.

Verification

  • No ctrl_c() remains in torrent_cleanup.rs.
  • Injected token cancellation produces Completion::Cancelled.
  • JobManager::cancel() reports named torrent_cleanup: JobStatus::Cancelled.
  • Direct-binary SIGTERM reports cleanup cancellation, not cleanup deadline abort.
  • Local functional scenario announces a peer, confirms it through the REST API, then confirms cleanup leaves the torrent known with "peers": []. The isolated configuration sets remove_peerless_torrents = false so this state is observable.

Full approved specification will be added in a separate spec-only pull request.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions