From 88161a64677076b189cef069fe7aaaeaa8199b5a Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Thu, 21 Nov 2024 13:56:22 +0300 Subject: [PATCH] Discard obsolete "state update" events after torrent is reloaded PR #21873. Closes #21827. --- src/base/bittorrent/torrentimpl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 5396ad0b0..ecfcb66e5 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -2635,6 +2635,12 @@ bool TorrentImpl::isMoveInProgress() const void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus) { + // Since libtorrent alerts are handled asynchronously there can be obsolete + // "state update" event reached here after torrent was reloaded in libtorrent. + // Just discard such events. + if (nativeStatus.handle != m_nativeHandle) [[unlikely]] + return; + const lt::torrent_status oldStatus = std::exchange(m_nativeStatus, nativeStatus); if (m_nativeStatus.num_pieces != oldStatus.num_pieces)