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

Program crash with large of downloading torrents #695

Closed uponatime2019 closed 2 months ago

uponatime2019 commented 2 months ago

I'm downloading +50 torrents at a time, program crash everytime it run 2-3 mins (ubuntu 20). I put everything in try catch but this still happen

Unexpected main loop exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoTorrent.Client.PeerExchangeManager.Populate(Int32 stride, Int32 maxPeers, Queue`1 addedPeers, Queue`1 droppedPeers) in C:\Projects\monotorre>
   at MonoTorrent.Client.PeerExchangeManager.OnTick() in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client\Managers\PeerExchangeManage>
   at MonoTorrent.Client.Modes.Mode.PostLogicTick(Int32 counter) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client.Modes\Mode.cs:li>
   at MonoTorrent.Client.Modes.DownloadMode.Tick(Int32 counter) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client.Modes\DownloadMod>
   at MonoTorrent.Client.ClientEngine.LogicTick() in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client\ClientEngine.cs:line 784
   at MonoTorrent.Client.ClientEngine.<.ctor>b__90_0() in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client\ClientEngine.cs:line 315
   at MonoTorrent.Client.MainLoop.<>c__DisplayClass10_0.<QueueTimeout>b__0(Object state) in C:\Projects\monotorrent\src\MainLoop.cs:line 137
   at MonoTorrent.Client.MainLoop.Loop() in C:\Projects\monotorrent\src\MainLoop.cs:line 78
alanmcgovern commented 2 months ago

Unexpected main loop exception: System.NullReferenceException: Object reference not set to an instance of an object. at MonoTorrent.Client.PeerExchangeManager.Populate(Int32 stride, Int32 maxPeers, Queue1 addedPeers, Queue1 droppedPeers) in C:\Projects\monotorre> at MonoTorrent.Client.PeerExchangeManager.OnTick() in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client\Managers\PeerExchangeManage> at MonoTorrent.Client.Modes.Mode.PostLogicTick(Int32 counter) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.Client.Modes\Mode.cs:li>

Hrm, that's interesting! Fortunately there's line numbers in the stacktrace - so could you just confirm which version of the package you're using and i'll see if i can find why that's happening!

alanmcgovern commented 2 months ago

Ah - whoops! The output is truncated on some lines so i'm missing the important line number(s)! If this happens again, can you increase the width of your terminal window (or wherever you got the stacktrace from) and get the full line for the top 2 stack frames. Specifcally, which line did this error occur on:

at MonoTorrent.Client.PeerExchangeManager.Populate(Int32 stride, Int32 maxPeers, Queue1 addedPeers, Queue1 droppedPeers) in C:\Projects\monotorre>

uponatime2019 commented 2 months ago

The output I included have line numbers already. It's happen at the latest version on Nuget (3.0.x)

alanmcgovern commented 2 months ago

@uponatime2019

Look at the stacktrace frames from 'PeerExchangeManager' - both of them are truncated and don't have the line number at the end.

The last few lines in the stacktrace (the shorter lines from MonoTorrent.Client.ClientEngine or MonoTorrent.Client.MainLoop) have the full line number information as they're not truncated.

There are no obvious/plausible null references in the PeerExchangeManager code so i'm a little confused as to what's happening, and the line number would be super useful

uponatime2019 commented 2 months ago

Sorry it always crash, with the Os is Ubuntu 20, not happen in Windows. And that's I got when look at journalctl

After that I downgrade library to version 2.0.x and it run OK in both Linux and Windows

alanmcgovern commented 2 months ago

I'm not sure if that particular patch will fix the issue, but the lack of obvious null refs combined with actual improper multi-threaded access seems like it could plausibly be the root cause!

If you can build from master i'd be curious to know if that fixes the issue. Otherwise i'll do another nuget release soon :)

alanmcgovern commented 2 months ago

@uponatime2019 Can you let me know if release 3.0.3-alpha.unstable.rev0049 fixes the issue you saw?