Discard obsolete "state update" events after torrent is reloaded

PR #21873.
Closes #21827.
This commit is contained in:
Vladimir Golovnev 2024-11-21 13:56:22 +03:00 committed by Vladimir Golovnev (glassez)
commit 71b752baf3
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7

View file

@ -2625,6 +2625,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)