This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 13e4fa25bd6aa422026a7571c90c183d51f774ec
Author: Brian Neradt <[email protected]>
AuthorDate: Tue Feb 3 17:21:29 2026 -0600

    Fix LoadedPlugins::remove crash during static destruction (#12854)
    
    When a PluginFactory is destroyed during static destruction (after main
    exits), the EThreads are already gone. LoadedPlugins::remove() was
    crashing because it tried to acquire a mutex lock using this_ethread(),
    which returns nullptr during static destruction.
    
    Now check if this_ethread() returns nullptr and handle cleanup directly
    in that case, since we're exiting anyway and don't need the mutex
    protection or scheduled deletion.
    
    This issue was discovered while testing the header_rewrite run-plugin
    feature, which creates a PluginFactory that persists as a static object
    and is destroyed during static destruction.
    
    (cherry picked from commit 16a93c9b76b3cf6669c1e3018f2fd7fa0898e846)
---
 src/proxy/http/remap/PluginDso.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/proxy/http/remap/PluginDso.cc 
b/src/proxy/http/remap/PluginDso.cc
index cd0499d8e6..5613251dad 100644
--- a/src/proxy/http/remap/PluginDso.cc
+++ b/src/proxy/http/remap/PluginDso.cc
@@ -330,10 +330,18 @@ PluginDso::LoadedPlugins::add(PluginDso *plugin)
 void
 PluginDso::LoadedPlugins::remove(PluginDso *plugin)
 {
-  SCOPED_MUTEX_LOCK(lock, _mutex, this_ethread());
+  EThread *ethread = this_ethread();
+  if (ethread == nullptr) {
+    // During static destruction, EThreads are gone. Just delete directly.
+    _list.erase(plugin);
+    delete plugin;
+    return;
+  }
+
+  SCOPED_MUTEX_LOCK(lock, _mutex, ethread);
 
   _list.erase(plugin);
-  this_ethread()->schedule_imm(new DeleterContinuation<PluginDso>(plugin));
+  ethread->schedule_imm(new DeleterContinuation<PluginDso>(plugin));
 }
 
 /* check if need to reload the plugin DSO

Reply via email to