Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race condition when cancelling requests after becoming a seed #7786

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading