summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Kalinich <AKalinich@luxoft.com>2020-04-28 21:51:47 -0400
committerAndrii Kalinich <AKalinich@luxoft.com>2020-06-23 14:39:48 -0400
commite98aff7471585813c3088007332d0fb772dfed7d (patch)
tree8408cfd8b60d4e1da45991b48878e32113e34242
parent73840c947b176476a7a68642d4a78cd270e270c1 (diff)
downloadsdl_core-fix/fix_button_subscriptions_mutex_deadlock.tar.gz
Fix mutex deadlock around app button subscriptionsfix/fix_button_subscriptions_mutex_deadlock
Sometimes there was observed mutex deadlock while more then one thread are accessing buttons subscriptions container protected with data accessor class. The issue is happening when one thread is trying to unregister application, acquires applications lock and trying to save application resumption data which at some point requires app subscribed buttons lock to be acquired. At the same moment another thread is trying to resume application data and acquires subscribed buttons accessor after which is trying to send notifications to HMI, which at some point requires applications lock to be acquired. When these two threads have a time intersection, mutex deadlock is happening. To resolve this deadlock, button subscription accessor has been replaced with temporary accessor + copying protected content to a local variable which allows to release that lock beforehand.
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc3
-rw-r--r--src/components/application_manager/src/resumption/resumption_data.cc19
2 files changed, 12 insertions, 10 deletions
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index d6fbed115b..2afecf037a 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -1108,8 +1108,7 @@ void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp(
return;
}
- DataAccessor<ButtonSubscriptions> button_accessor = app->SubscribedButtons();
- ButtonSubscriptions subscriptions = button_accessor.GetData();
+ const ButtonSubscriptions subscriptions = app->SubscribedButtons().GetData();
ButtonSubscriptions::iterator it = subscriptions.begin();
for (; subscriptions.end() != it; ++it) {
SendOnButtonSubscriptionNotification(
diff --git a/src/components/application_manager/src/resumption/resumption_data.cc b/src/components/application_manager/src/resumption/resumption_data.cc
index 9046fe35ad..0312975fec 100644
--- a/src/components/application_manager/src/resumption/resumption_data.cc
+++ b/src/components/application_manager/src/resumption/resumption_data.cc
@@ -148,20 +148,23 @@ smart_objects::SmartObject ResumptionData::GetApplicationSubscriptions(
}
LOG4CXX_DEBUG(logger_, "app_id:" << application->app_id());
- DataAccessor<ButtonSubscriptions> button_accessor =
- application->SubscribedButtons();
+ {
+ DataAccessor<ButtonSubscriptions> button_accessor =
+ application->SubscribedButtons();
- const ButtonSubscriptions& button_subscriptions = button_accessor.GetData();
+ const ButtonSubscriptions& button_subscriptions = button_accessor.GetData();
- LOG4CXX_DEBUG(logger_, "SubscribedButtons:" << button_subscriptions.size());
- Append(button_subscriptions.begin(),
- button_subscriptions.end(),
- strings::application_buttons,
- subscriptions);
+ LOG4CXX_DEBUG(logger_, "SubscribedButtons:" << button_subscriptions.size());
+ Append(button_subscriptions.begin(),
+ button_subscriptions.end(),
+ strings::application_buttons,
+ subscriptions);
+ }
for (auto extension : application->Extensions()) {
extension->SaveResumptionData(subscriptions);
}
+
return subscriptions;
}