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 6eac918
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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
5 changes: 4 additions & 1 deletion 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
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 @@ -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);
Expand Down

0 comments on commit 6eac918

Please sign in to comment.