From acf423d42290d14fa86a860ec686c3cdc72ac40f Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Tue, 12 May 2015 18:39:21 -0700 Subject: [PATCH] Release alert manager mutex before notifying plugins A plugin might respond to an alert by doing something which itself generates an alert. This has become increasingly likely with the use of alerts for logging. This would cause a deadlock due to trying to recursively aquire the alert manager mutex. --- src/alert_manager.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/alert_manager.cpp b/src/alert_manager.cpp index 67e660608..a9fb5790a 100644 --- a/src/alert_manager.cpp +++ b/src/alert_manager.cpp @@ -73,13 +73,6 @@ namespace libtorrent void alert_manager::maybe_notify(alert* a, mutex::scoped_lock& lock) { -#ifndef TORRENT_DISABLE_EXTENSIONS - for (ses_extension_list_t::iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) - { - (*i)->on_alert(a); - } -#endif if (a->type() == save_resume_data_failed_alert::alert_type || a->type() == save_resume_data_alert::alert_type) ++m_num_queued_resume; @@ -98,6 +91,18 @@ namespace libtorrent // > 0 notify them m_condition.notify_all(); } + else + { + lock.unlock(); + } + +#ifndef TORRENT_DISABLE_EXTENSIONS + for (ses_extension_list_t::iterator i = m_ses_extensions.begin() + , end(m_ses_extensions.end()); i != end; ++i) + { + (*i)->on_alert(a); + } +#endif } #ifndef TORRENT_NO_DEPRECATE