Skip to content

Commit

Permalink
fix race condition when cancelling requests after becoming a seed
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Nov 9, 2024
1 parent f9dde82 commit 42e8f9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

2.0.11 not released

* fix race condition when cancelling requests after becoming a seed
* fix performance bug in the file pool, evicting MRU instead of LRU (HanabishiRecca)
* fix bug where file_progress could sometimes be reported as >100%
* don't hint FADV_RANDOM on posix systems. May improve seeding performance
Expand Down
7 changes: 5 additions & 2 deletions src/peer_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3200,9 +3200,11 @@ namespace libtorrent {
{
// if any other peer has a busy request to this block, we need
// to cancel it too
t->cancel_block(block_finished);
if (t->has_picker())
{
t->cancel_block(block_finished);
t->picker().write_failed(block_finished);
}

if (t->has_storage())
{
Expand Down Expand Up @@ -3751,6 +3753,7 @@ namespace libtorrent {
TORRENT_ASSERT(block.piece_index != piece_block::invalid.piece_index);
TORRENT_ASSERT(block.piece_index < t->torrent_file().end_piece());
TORRENT_ASSERT(block.block_index < t->torrent_file().piece_size(block.piece_index));
TORRENT_ASSERT(t->has_picker());

// if all the peers that requested this block has been
// cancelled, then just ignore the cancel.
Expand Down Expand Up @@ -4034,7 +4037,7 @@ namespace libtorrent {
INVARIANT_CHECK;

std::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
if (!t) return;

if (m_disconnecting) return;

Expand Down
6 changes: 6 additions & 0 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5094,6 +5094,10 @@ namespace {
#ifndef TORRENT_DISABLE_STREAMING
void torrent::cancel_non_critical()
{
// if we don't have a piece picker, there's nothing to cancel.
// e.g. We may have become a seed already.
if (!has_picker()) return;

std::set<piece_index_t> time_critical;
for (auto const& p : m_time_critical_pieces)
time_critical.insert(p.piece);
Expand Down Expand Up @@ -5989,6 +5993,8 @@ namespace {
{
INVARIANT_CHECK;

TORRENT_ASSERT(has_picker());

for (auto p : m_connections)
{
TORRENT_INCREMENT(m_iterating_connections);
Expand Down

0 comments on commit 42e8f9e

Please sign in to comment.