From e851b7986583499e11c34aa0dd790c6b11d57f7e Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 2 Mar 2016 01:16:08 -0500 Subject: [PATCH] fix issue when shutting down a torrent with outstanding async operations --- src/session_impl.cpp | 4 ++-- src/torrent.cpp | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index dc87c438a..07c7270df 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3438,7 +3438,7 @@ retry: 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; - v |= v >> 1; // first round down to one less than a power of 2 + v |= v >> 1; // first round down to one less than a power of 2 v |= v >> 2; v |= v >> 4; v |= v >> 8; @@ -5058,7 +5058,7 @@ retry: // we have specific outgoing interfaces specified. Make sure the // local endpoint for this socket is bound to one of the allowed // interfaces. the list can be a mixture of interfaces and IP - // addresses. first look for the address + // addresses. first look for the address for (int i = 0; i < int(m_net_interfaces.size()); ++i) { error_code err; diff --git a/src/torrent.cpp b/src/torrent.cpp index 0a016cce0..e51edbc66 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1258,6 +1258,8 @@ namespace libtorrent TORRENT_UNUSED(j); TORRENT_UNUSED(b); + if (m_abort) return; + update_gauge(); // some peers that previously was no longer interesting may // now have become interesting, since we lack this one piece now. @@ -2325,6 +2327,8 @@ namespace libtorrent return; } + if (m_abort) return; + state_updated(); if (m_resume_data && m_resume_data->node.type() == bdecode_node::dict_t) @@ -2647,6 +2651,8 @@ namespace libtorrent dec_refcount("force_recheck"); state_updated(); + if (m_abort) return; + if (j->ret == piece_manager::fatal_disk_error) { handle_disk_error(j); @@ -2727,6 +2733,8 @@ namespace libtorrent dec_refcount("start_checking"); + if (m_abort) return; + if (j->ret == piece_manager::disk_check_aborted) { m_checking_piece = 0; @@ -3041,6 +3049,7 @@ namespace libtorrent , int(peers.size())); #endif + if (m_abort) return; if (peers.empty()) return; if (m_ses.alerts().should_post()) @@ -3752,7 +3761,7 @@ namespace libtorrent if (ec) debug_log("i2p_resolve error: %s", ec.message().c_str()); #endif - if (ec || m_ses.is_aborted()) return; + if (ec || m_abort || m_ses.is_aborted()) return; need_peer_list(); torrent_state st = get_peer_list_state(); @@ -3778,7 +3787,7 @@ namespace libtorrent debug_log("peer name lookup error: %s", e.message().c_str()); #endif - if (e || host_list.empty() || m_ses.is_aborted()) return; + if (e || m_abort || host_list.empty() || m_ses.is_aborted()) return; // TODO: add one peer per IP the hostname resolves to tcp::endpoint host(host_list.front(), port); @@ -4124,6 +4133,8 @@ namespace libtorrent dec_refcount("verify_piece"); + if (m_abort) return; + int ret = j->ret; if (settings().get_bool(settings_pack::disable_hash_checks)) { @@ -10555,6 +10566,7 @@ namespace libtorrent update_want_peers(); } + // TODO: 2 this should probably be removed void torrent::refresh_explicit_cache(int cache_size) { TORRENT_ASSERT(is_single_thread());