stallwatcher

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stallwatcher is the Pilot-side consumer of Haul's stall detection.

Every 60 seconds it polls Haul's /api/v1/stalls endpoint, correlates each stalled torrent with a grab_history row (via info_hash), writes a blocklist entry for the release (reason tagged with the stall type), and marks the grab as stalled. If the grab was triggered by auto-search, the watcher also triggers a re-search for the episode, capped by a circuit breaker to avoid loops when every release for an episode is dead.

Design notes in plans/dead-torrent-phase0.md. Specifically: this is pull-based (not webhooks), runs entirely in Pilot, and tolerates Haul being briefly unreachable without fallout. The watcher does NOT blocklist during its own first 2 minutes of uptime — that's to absorb restart races where grabs from before the restart look "stalled" because we just haven't observed them yet.

⚠ Before changing anything in this file, run:

go test ./internal/core/stallwatcher/...

The tests (service_test.go) pin every critical contract:

  • startup grace suppression
  • circuit breaker behavior
  • interactive-vs-auto_search retry gating
  • unique-info_hash cross-indexer dedup
  • idempotency on already-stalled grabs
  • graceful degradation when Haul is down

See pilot/CLAUDE.md for the full regression-guard rationale.

Index

Constants

View Source
const MaxStallRetriesPerEpisode = 3

MaxStallRetriesPerEpisode is the circuit breaker: after this many stall-reason blocklist entries for a (series, episode) in the last 24 hours, auto-re-search stops. Prevents infinite loops when every release for an episode happens to be dead.

View Source
const StaleGrabAge = 24 * time.Hour

StaleGrabAge is how long a grab can sit in `downloading` / `queued` / `pending` without an info_hash before the sweep marks it failed. The info_hash-less branch is invisible to the haul-stall path (haul keys stalls by info_hash), so the only signal we have is age. 24h is well past any normal "metadata fetch + tracker announce + first peer" startup, and it leaves a generous window for genuinely-slow first connects on remote VPN endpoints.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service polls Haul for stalled torrents and reacts by blocklisting the corresponding release.

func NewService

func NewService(
	q db.Querier,
	blocklist *blocklist.Service,
	downloader *downloader.Service,
	bus *events.Bus,
	logger *slog.Logger,
) *Service

NewService constructs a stallwatcher Service. Call Run in a goroutine.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run is a blocking poll loop. Returns when ctx is canceled.

func (*Service) Tick

func (s *Service) Tick(ctx context.Context) error

Tick runs one poll cycle. Exposed for tests and manual invocation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL