diff --git a/ChangeLog b/ChangeLog index 62433647b..060d2cc67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ incoming connection * added more detailed instrumentation of the disk I/O thread + * fixed potential issue where a piece could be checked twice * fixed build issue on windows related to GetCompressedSize() * fixed deadlock when starting torrents with certain invalid tracker URLs * fixed iterator bug in disk I/O thread diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index e87c84475..085e47d60 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2352,6 +2352,7 @@ namespace libtorrent m_timeout_extend = 0; } + bool was_finished = picker.is_piece_finished(p.piece); // did we request this block from any other peers? bool multi = picker.num_peers(block_finished) > 1; picker.mark_as_writing(block_finished, peer_info_struct()); @@ -2370,7 +2371,7 @@ namespace libtorrent // did we just finish the piece? // this means all blocks are either written // to disk or are in the disk write cache - if (picker.is_piece_finished(p.piece)) + if (picker.is_piece_finished(p.piece) && !was_finished) { #ifdef TORRENT_DEBUG check_postcondition post_checker2_(t, false); diff --git a/src/torrent.cpp b/src/torrent.cpp index 08f48f615..43e9fecc1 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -677,6 +677,8 @@ namespace libtorrent // avoid crash trying to access the picker when there is nont if (is_seed()) return; + if (picker().have_piece(piece)) return; + peer_request p; p.piece = piece; p.start = 0; @@ -739,13 +741,6 @@ namespace libtorrent m_need_save_resume_data = true; picker().mark_as_finished(block_finished, 0); - - // did we just finish the piece? - if (picker().is_piece_finished(p.piece)) - { - async_verify_piece(p.piece, bind(&torrent::piece_finished, shared_from_this() - , p.piece, _1)); - } } void torrent::on_disk_cache_complete(int ret, disk_io_job const& j) @@ -2106,6 +2101,8 @@ namespace libtorrent TORRENT_ASSERT(valid_metadata()); + TORRENT_ASSERT(!m_picker->have_piece(index)); + // even though the piece passed the hash-check // it might still have failed being written to disk // if so, piece_picker::write_failed() has been