From dd02deb28b8aea98bd22fd56838cb1aad93c4a46 Mon Sep 17 00:00:00 2001 From: SatheeshkumarG15 Date: Tue, 21 Apr 2026 17:32:22 +0530 Subject: [PATCH 1/2] Used an atomic bool and compare_exchange_strong to make sure either ResourceMonitor or Workerpool thread to properly clear out the service and to avoid the crash --- Source/Thunder/PluginServer.cpp | 5 +---- Source/Thunder/PluginServer.h | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Source/Thunder/PluginServer.cpp b/Source/Thunder/PluginServer.cpp index eea2d7c86..7651c2e93 100644 --- a/Source/Thunder/PluginServer.cpp +++ b/Source/Thunder/PluginServer.cpp @@ -1214,11 +1214,8 @@ namespace PluginHost { TRACE(Activity, (_T("Destruct a link with ID [%d] to [%s]"), Id(), RemoteId().c_str())); // If we are still atatched to a service, detach, we are out of scope... - if (_service.IsValid() == true) { - _service->Unsubscribe(*this); + CleanupService(); - _service.Release(); - } if (_security != nullptr) { _security->Release(); _security = nullptr; diff --git a/Source/Thunder/PluginServer.h b/Source/Thunder/PluginServer.h index 674d2d849..35b69fbfe 100644 --- a/Source/Thunder/PluginServer.h +++ b/Source/Thunder/PluginServer.h @@ -25,6 +25,7 @@ #include "IRemoteInstantiation.h" #include "WarningReportingCategories.h" #include "PostMortem.h" +#include #ifndef HOSTING_COMPROCESS #error "Please define the name of the COM process!!!" @@ -5353,11 +5354,8 @@ namespace PluginHost { // If we are closing (or closed) do the clean up if (IsOpen() == false) { - if (_service.IsValid() == true) { - _service->Detach(*this); - _service.Release(); - } + CleanupService(); State(CLOSED, false); @@ -5427,11 +5425,24 @@ namespace PluginHost { SetId(id); } + void CleanupService() + { + bool expected = false; + if (_serviceCleanedUp.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) { + if (_service.IsValid() == true) { + _service->Unsubscribe(*this); + _service->Detach(*this); + _service.Release(); + } + } + } + Server& _parent; PluginHost::ISecurity* _security; Core::ProxyType _service; bool _requestClose; Jobs _jobs; + std::atomic _serviceCleanedUp{false}; // Factories for creating jobs that can be placed on the PluginHost Worker pool. static Core::ProxyPoolType _webJobs; From 0e7f6cf21cc93ad04cdd949106cdcf8e905d3d84 Mon Sep 17 00:00:00 2001 From: SatheeshkumarG15 Date: Wed, 22 Apr 2026 15:31:27 +0530 Subject: [PATCH 2/2] Moving atomic variable to Channel class member Initialiser list --- Source/Thunder/PluginServer.cpp | 1 + Source/Thunder/PluginServer.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Thunder/PluginServer.cpp b/Source/Thunder/PluginServer.cpp index 7651c2e93..b86da1bbd 100644 --- a/Source/Thunder/PluginServer.cpp +++ b/Source/Thunder/PluginServer.cpp @@ -1203,6 +1203,7 @@ namespace PluginHost { , _service() , _requestClose(false) , _jobs() + , _serviceCleanedUp(false) { TRACE(Activity, (_T("Construct a link with ID: [%d] to [%s]"), Id(), remoteId.QualifiedName().c_str())); diff --git a/Source/Thunder/PluginServer.h b/Source/Thunder/PluginServer.h index 35b69fbfe..56ec288ee 100644 --- a/Source/Thunder/PluginServer.h +++ b/Source/Thunder/PluginServer.h @@ -5442,7 +5442,7 @@ namespace PluginHost { Core::ProxyType _service; bool _requestClose; Jobs _jobs; - std::atomic _serviceCleanedUp{false}; + std::atomic _serviceCleanedUp; // Factories for creating jobs that can be placed on the PluginHost Worker pool. static Core::ProxyPoolType _webJobs;