[WRTjs][VD] Waitting ReallaunchWorker thread exit before app is terminated 51/315551/2
authorzhaosy <shiyusy.zhao@samsung.com>
Fri, 22 Nov 2024 09:02:31 +0000 (17:02 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 3 Dec 2024 05:43:17 +0000 (05:43 +0000)
Both in main thread and ReallaunchWorker thread, security manager api is used.
If main thread exit, but ReallaunchWorker still is calling security manager api,
then the global variate of security manager is destroyed, but ReallaunchWorker
still is using it, then app is crashed.

So before app is terminated,join ReallaunchWorker thread.

Change-Id: I528f39e77e72ddd1bafc23571d27a3fde4a235cd
Signed-off-by: zhaosy <shiyusy.zhao@samsung.com>
wrt/src/app/tv/wrt_main_delegate_tv.cc
wrt/src/app/tv/wrt_main_delegate_tv.h
wrt/src/browser/tv/native_web_runtime_delegate_tv.cc

index ccfe005504fb4f125d115bef4f194c9ae2043692..82aa6e7d21140134e4ca3cbae744891668ab9356 100644 (file)
@@ -86,6 +86,7 @@ const char* kZoneLibPath = LIB_PATH "/libzone.so.5";
 
 std::mutex prelaunch_mutex;
 std::mutex reallaunch_mutex;
+std::thread reallaunch_worker;
 std::string prelaunch_pkg_id;
 base::Lock loader_complete_lock;
 
@@ -238,6 +239,14 @@ void WRTMainDelegateTV::GroupZygoteProcess(bool is_oom) {
 #endif
 }
 
+// static
+void WRTMainDelegateTV::ReallaunchWorkerJoin() {
+  if (reallaunch_worker.joinable())
+    reallaunch_worker.join();
+
+  LOG(INFO) << "ReallaunchWorker thread exit";
+}
+
 void WRTMainDelegateTV::AdjustloaderPriority(
     const std::string& loader_work,
     const std::string& reallaunch_work) {
@@ -273,7 +282,7 @@ void WRTMainDelegateTV::CreateWorkers() {
   });
   prelaunch_worker.detach();
 
-  std::thread reallaunch_worker([]() -> void {
+  reallaunch_worker = std::thread([]() -> void {
     InitializeBeforeRealLaunch();
     // ensure thread safe
     AdjustloaderPriority("", "ready");
@@ -289,8 +298,6 @@ void WRTMainDelegateTV::CreateWorkers() {
     GroupZygoteProcess(false);
     reallaunch_mutex.unlock();
   });
-  reallaunch_worker.detach();
-
 }
 
 void WRTMainDelegateTV::LoaderCreated() {
index 97c911d9f6b80374f665cb582edb6b1816fd1042..4e93cd7fca4ae7d9902985a98807279aeb66cc5e 100644 (file)
@@ -19,6 +19,7 @@ class WRTMainDelegateTV : public WRTMainDelegate {
   ~WRTMainDelegateTV() {}
 
   static void GroupZygoteProcess(bool is_oom);
+  static void ReallaunchWorkerJoin();
 
  private:
   absl::optional<int> BasicStartupComplete() override;
index 14c9f9f7533f8672b77d0bb97a550594006b815b..c77c996ad6a6b4e0503958e979c2f9a2791fed7a 100644 (file)
@@ -357,6 +357,7 @@ void NativeWebRuntimeDelegateTV::Finalize() {
     LOG(WARNING) << "failed to unregister state changed event callback";
   ClearTmpFolder();
   ApplicationDataTV::GetInstance().StorePreconnectURL();
+  WRTMainDelegateTV::ReallaunchWorkerJoin();
 }
 
 void NativeWebRuntimeDelegateTV::RequestQuit() {