fix: a release its download client will not let Minstrel follow is held back, not taken every pass (#6176)
release / govulncheck (push) Successful in 16s
release / web (push) Successful in 1m21s
release / go (push) Successful in 1m34s
release / integration (push) Successful in 5m5s
release / android (push) Successful in 5m7s
release / Build signed APK (releases and dev) (push) Successful in 5m14s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 22s
release / Verify release artifacts (tag releases only) (push) Skipped

The Black Keys' Ohio Players was grabbed 40 times in a day. FabledExchange
already held the torrent under another category from before Minstrel took
the downloads over: the add answered "duplicate", which counted as added,
and Exchange's listing, filtered to Minstrel's category, never showed it.
Half an hour later the grab ended gone, and the next pass took it again.

- A duplicate add that the client does not list for Minstrel is not a
  grab: the release is held back for a day with the client's own reason
  (already downloading X (category)), and the search moves on. Forced,
  it is refused with that reason.
- A release that ends gone a second time within a week is held back for
  a day, whatever the cause.
- release_blocks gains the reason 'gone' (migration 0098), shown as
  "Held back: its download client lost track of it".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 11:31:57 -04:00
co-authored by Claude Opus 5.5
parent cb1f619a21
commit 484a81f779
11 changed files with 186 additions and 3 deletions
+26 -1
View File
@@ -75,6 +75,8 @@ const (
// goneAfter: a client restarting can answer without a download for a
// while; half an hour missing is gone.
goneAfter = 30 * time.Minute
// goneWindow: a release gone twice within it is held back (#6176).
goneWindow = 7 * 24 * time.Hour
)
// running are the import states of a grab still downloading: the lifecycle
@@ -441,12 +443,35 @@ func (s *Service) giveUp(ctx context.Context, q *dbq.Queries, d downloader.Drive
}
// endGone ends a grab whose download left the client, and searches again.
// The release is not held back: nothing was found wrong with it.
// The first time, the release is not held back: nothing was found wrong with
// it. A release that leaves its client again within goneWindow is held back for
// acquire.GoneBlock (#6176): whatever keeps the client from listing it, taking
// it again on every pass found 38 grabs of one release in a day.
func (s *Service) endGone(ctx context.Context, q *dbq.Queries, g dbq.ListLiveGrabsRow, rep *Report) {
detail := "The download client no longer lists it: removed outside Minstrel. The album is searched for again."
before, err := q.CountGoneGrabs(ctx, dbq.CountGoneGrabsParams{
InfoHash: g.InfoHash, Since: pgtype.Timestamptz{Time: s.now().Add(-goneWindow), Valid: true}})
if err != nil {
s.logger.Warn("lifecycle: count earlier gone grabs", "grab", g.Name, "err", err)
}
again := before > 0
until := s.now().Add(acquire.GoneBlock)
if again {
detail = fmt.Sprintf("The download client no longer lists it, again: held back until %s; the album is searched for again.",
until.Format("2 Jan 15:04"))
}
if _, err := q.GiveUpGrab(ctx, dbq.GiveUpGrabParams{ID: g.ID, EndReason: EndGone, EndDetail: detail, States: running}); err != nil {
return
}
if again {
if err := acquire.NewMemory(s.pool).Block(ctx, dbq.BlockReleaseParams{
InfoHash: g.InfoHash, Name: g.Name, Reason: acquire.BlockGone,
Detail: "It left its download client twice without finishing.",
WantID: g.WantID, ExpiresAt: pgtype.Timestamptz{Time: until, Valid: true},
}); err != nil {
s.logger.Warn("lifecycle: hold the release back", "grab", g.Name, "err", err)
}
}
if g.WantID.Valid {
if err := q.SearchWantAgain(ctx, g.WantID); err != nil {
s.logger.Warn("lifecycle: search again", "grab", g.Name, "err", err)
+47
View File
@@ -6,6 +6,7 @@ import (
"io"
"log/slog"
"os"
"strings"
"testing"
"time"
@@ -277,6 +278,52 @@ func TestLifecycle_ADownloadGoneFromTheClientEndsAfterHalfAnHour_Integration(t *
}
}
// A release that leaves its client a second time is held back, whatever the
// cause (#6176): one release was taken 40 times in a day, each ending gone.
func TestLifecycle_AReleaseGoneTwiceIsHeldBack_Integration(t *testing.T) {
st := newStack(t, downloader.Torrent{Name: "Daft Punk - RAM [FLAC]", Progress: 0.3, State: "downloading", NumSeeds: 4})
ctx := context.Background()
delete(st.client.held, hash)
st.client.held[other] = downloader.Torrent{Hash: other, Name: "Someone else's", Progress: 1, State: "uploading"}
st.s.Pass(ctx)
st.clock = st.clock.Add(31 * time.Minute)
if rep := st.s.Pass(ctx); rep.Gone != 1 {
t.Fatalf("first gone: %+v", rep)
}
if blocks, _ := st.q.ListReleaseBlocks(ctx); len(blocks) != 0 {
t.Fatalf("held back after one gone: %+v", blocks)
}
again, err := acquire.NewMemory(st.s.pool).Grabbed(ctx, dbq.InsertGrabParams{WantID: st.want.ID, InfoHash: hash,
Name: "Daft Punk - RAM [FLAC]", Key: hash, Client: "qbittorrent", SavePath: "/downloads", Origin: acquire.OriginSchedule},
pgtype.UUID{}, "")
if err != nil {
t.Fatal(err)
}
// first_seen is the database's clock and the test's runs ahead of it, so
// the second grab may end on either pass; count both.
gone := st.s.Pass(ctx).Gone
st.clock = st.clock.Add(31 * time.Minute)
if gone += st.s.Pass(ctx).Gone; gone != 1 {
t.Fatalf("second grab ended gone %d times, want 1", gone)
}
blocks, err := st.q.ListReleaseBlocks(ctx)
if err != nil {
t.Fatal(err)
}
if len(blocks) != 1 || blocks[0].Reason != acquire.BlockGone || !blocks[0].ExpiresAt.Valid {
t.Fatalf("blocks = %+v, want one timed gone block", blocks)
}
g, err := st.q.GetGrab(ctx, again.ID)
if err != nil {
t.Fatal(err)
}
if g.EndReason != EndGone || !strings.Contains(g.EndDetail, "held back until") {
t.Errorf("second grab %q: %s", g.EndReason, g.EndDetail)
}
}
func TestLifecycle_AnEmptyListIsNotAMeasurement_Integration(t *testing.T) {
st := newStack(t, downloader.Torrent{Name: "Daft Punk - RAM [FLAC]", Progress: 0.3, State: "downloading"})
ctx := context.Background()