From: Ji-hoon Lee Date: Thu, 30 Mar 2023 11:25:22 +0000 (+0900) Subject: Make sure the process would not be restarted too frequently X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_7.0;p=platform%2Fcore%2Fuifw%2Fmulti-assistant-service.git Make sure the process would not be restarted too frequently If an auto-restart process gets restarted more than 5 times in 10 seconds, it is considered to be an abnormal behavior and will not be restarted automatically anymore. For this reason, modified the app_restart() function to sleep if the application tries to restart in less than 3 seconds from the time it was launched. Change-Id: Ie85194792edd706220a15b224ee4a3e184e2e02d --- diff --git a/inc/service_main.h b/inc/service_main.h index 135e3d4..5d774f9 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -18,6 +18,7 @@ #ifndef __SERVICE_MAIN_H__ #define __SERVICE_MAIN_H__ +#include #include #include @@ -226,6 +227,8 @@ private: IPreferenceManager& mPreferenceManager; pid_t mLastDuckingRequester{-1}; + + std::chrono::time_point mStartedTime; }; #endif /* __SERVICE_MAIN_H__ */ diff --git a/src/service_main.cpp b/src/service_main.cpp index 7858a88..eaada08 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -25,10 +25,10 @@ #include #include -#include #include #include #include +#include #include #include @@ -1387,6 +1387,7 @@ bool CServiceMain::app_create(void *data) // Todo: add your code here. MAS_LOGE("[ENTER] Service app create"); + mStartedTime = std::chrono::steady_clock::now(); g_service_main = this; mClientManager.set_application_manager(&mApplicationManager); @@ -1464,7 +1465,24 @@ void CServiceMain::app_terminate(void *data) void CServiceMain::app_restart() { + MAS_LOGE("[ENTER]"); + + /* It would be best if we could sleep only when the current restart request + * is the 5th operation within 10 seconds, however we don't have a way to + * determine the number of restart operations since such information has to be + * stored externally but there isn't appropriate place to store it at the moment. */ + const std::chrono::seconds minimum_interval(3); + auto interval = std::chrono::steady_clock::now() - mStartedTime; + if (interval < minimum_interval) { + MAS_LOGE("sleeping for %lld ms", + std::chrono::duration_cast(minimum_interval - interval).count()); + std::this_thread::sleep_for(minimum_interval - interval); + } else { + MAS_LOGE("interval is %lld ms, no need to sleep", + std::chrono::duration_cast(interval).count()); + } mServiceIpc.send_restart_notification(); + service_app_exit(); }