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 GitHub
parent 7f901a812d
commit 88161a6467
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)