diff --git a/ChangeLog b/ChangeLog index 0a68b98147..5a5b4c350a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index d3a1278eaf..35e36b8b0c 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -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()) { @@ -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. diff --git a/src/torrent.cpp b/src/torrent.cpp index 7a21969091..f323b26cc5 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -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 time_critical; for (auto const& p : m_time_critical_pieces) time_critical.insert(p.piece); @@ -5949,6 +5953,8 @@ namespace { { INVARIANT_CHECK; + TORRENT_ASSERT(has_picker()); + TORRENT_ASSERT(!c.is_choked()); TORRENT_ASSERT(!c.ignore_unchoke_slots()); TORRENT_ASSERT(m_num_uploads > 0);