alanmcgovern / monotorrent

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

Ensure pending messages are processed from the send queue regularly #673

Closed alanmcgovern closed 3 months ago

alanmcgovern commented 3 months ago

This fixes a race condition where peers would sometimes get stuck while fetching bittorrent v2 hashes, depending on the timing of when the first request was made and then the final part of the handshake completed.

If requests were enqueued early, everything was fine. If requests were queued late, then nothing would kick off the queue consumer and enqueued messages would be left pending until the peer timed out, or until a KeepAlive message was sent which would unblock the queue.

Addresses issues like https://github.com/alanmcgovern/monotorrent/issues/672

peerlessDJ commented 3 months ago

emmm,is there no way to optimize it further? The first time to download from torrent file, it always get this problem

alanmcgovern commented 3 months ago

That depends on what you mean. If you're wondering if hashes can be fetched faster - try the fix first. Performance will improve because messages will actually be sent to other peers after they're queued.

If there's another issue - could you open a new issue describing the particular performance issue you experience?