alanmcgovern / monotorrent

The official repository for MonoTorrent, a bittorrent library for .NET
https://github.com/alanmcgovern/monotorrent
MIT License
1.15k stars 397 forks source link

From `FetchingHashes` to `Downloading` for V2 is so slow #672

Closed peerlessDJ closed 3 months ago

peerlessDJ commented 3 months ago
TorrentManager torrentManager = await _clientEngine.AddAsync(pArgs.Torrent, pArgs.SavePath);
foreach (var file in torrentManager.Files)
{
    var torrentItem = pArgs.TorrentItems.FirstOrDefault(item => item.TorrentFile.Path == file.Path);
    await torrentManager.SetFilePriorityAsync(file, torrentItem != null ? (Priority)torrentItem.Priority : Priority.DoNotDownload);
}

torrentManager.TorrentStateChanged += delegate (object o, TorrentStateChangedEventArgs e) 
{
    Debug.WriteLine($"TorrentStateChanged----OldState: [{e.OldState}]   NewState: [{e.NewState}]  DateTime:[{DateTime.Now.ToString()}]");
};

await torrentManager.StartAsync();

The log is

TorrentStateChanged----OldState: [Stopped]   NewState: [Starting]  DateTime:[2024/8/9 15:03:18]
TorrentStateChanged----OldState: [Starting]   NewState: [Hashing]  DateTime:[2024/8/9 15:03:18]
TorrentStateChanged----OldState: [Hashing]   NewState: [FetchingHashes]  DateTime:[2024/8/9 15:03:18]
TorrentStateChanged----OldState: [FetchingHashes]   NewState: [Downloading]  DateTime:[2024/8/9 15:05:28]

from FetchingHashes to Downloading wait 2 minutes

alanmcgovern commented 3 months ago

Ah - I think I see the issue.

There's a bug whereby hash request messages are enqueued to send to a peer, but the never begins processing, and so the requests are left there until the timeout is reached.

whoops