Magnet waiting for metadata can freeze the downloader

Open
#1,609 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
dart, go
Domain
backend

Research direction

Start by reading internal/protocol/bt/fetcher.go around Resolve and pkg/download/downloader.go around the start handler, runPauseHandler, Continue, and pauseAll. Trace which locks are held while metadata resolution waits and how cancellation or pausing interacts with those locks. Done means a magnet waiting for metadata can be paused, and the described downloader operations do not remain blocked; add focused tests for those cases.

Written by the indexing model from the issue text.

Description

Description(required)

A magnet with no peers keeps Resolve waiting on GotInfo with no timeout (internal/protocol/bt/fetcher.go:844-851). The start handler holds task.lock across Resolve and Start (pkg/download/downloader.go:1999-2059), so:

  • Pause on that task hangs, because runPauseHandler takes task.lock first (:2148). BT Pause would also wait on f.mu, which Resolve holds.
  • When MaxRunning is reached, Continue on another task pauses this one while holding d.lock (:809-836). GetTasks, Create, Delete and the progress loop then block too.
  • Close runs pauseAll before fm.Close (:1236-1239), so quitting may hang as well. I found this by reading only.

With a fake fetcher whose Resolve blocks, GetTasks stayed blocked for over 1 s after Continue. In the BT fetcher, Pause stayed blocked for over 3 s while Resolve waited, and returned right after Close.

A possible fix is to let Pause cancel the metadata wait and to pause tasks in Continue after releasing d.lock. That changes lock ordering, so I'd like your view before sending a PR.

App Version(required)

main (b8ff5ff)

OS Version(required)

macOS 27 (not OS specific)

Dominant language
Dart
Stars
27.7k
Forks
1.8k
Avg merge
3d 3h
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GopeedLab/gopeed

All issues in GopeedLab/gopeed

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.