From b9546ccd4ce579cfe65af673158ee631591d0346 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Mon, 21 May 2018 01:09:58 +0300 Subject: [PATCH] Suppress multiple I/O errors for the same torrent When a file error happens libtorrent spews a ton of `file_error_alert` which result in log floods and notification balloon floods. The later might render the program inaccessible because the constant notifications prevent the user from interacting with the tray icon. Closes #8934 --- src/base/bittorrent/session.cpp | 18 ++++++++++++++---- src/base/bittorrent/session.h | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index a228349ac..d5b8cdd0c 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -370,11 +370,16 @@ Session::Session(QObject *parent) , m_numResumeData(0) , m_extraLimit(0) , m_useProxy(false) + , m_recentErroredTorrentsTimer(new QTimer(this)) { Logger *const logger = Logger::instance(); initResumeFolder(); + m_recentErroredTorrentsTimer->setSingleShot(true); + m_recentErroredTorrentsTimer->setInterval(1000); + connect(m_recentErroredTorrentsTimer, &QTimer::timeout, this, [this]() { m_recentErroredTorrents.clear(); }); + m_seedingLimitTimer = new QTimer(this); m_seedingLimitTimer->setInterval(10000); connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits); @@ -4184,10 +4189,15 @@ void Session::handleFileErrorAlert(libt::file_error_alert *p) // NOTE: Check this function! TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash()); if (torrent) { - QString msg = QString::fromStdString(p->message()); - Logger::instance()->addMessage(tr("An I/O error occurred, '%1' paused. %2") - .arg(torrent->name(), msg)); - emit fullDiskError(torrent, msg); + const InfoHash hash = torrent->hash(); + if (!m_recentErroredTorrents.contains(hash)) { + m_recentErroredTorrents.insert(hash); + const QString msg = QString::fromStdString(p->message()); + LogMsg(tr("An I/O error occurred, '%1' paused. %2").arg(torrent->name(), msg)); + emit fullDiskError(torrent, msg); + } + + m_recentErroredTorrentsTimer->start(); } } diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 53f557d80..dec225a73 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -761,6 +761,10 @@ namespace BitTorrent QStringMap m_categories; QSet m_tags; + // I/O errored torrents + QSet m_recentErroredTorrents; + QTimer *m_recentErroredTorrentsTimer; + #if LIBTORRENT_VERSION_NUM < 10100 QMutex m_alertsMutex; QWaitCondition m_alertsWaitCondition;