Skip to content

Commit 16a93c9

Browse files
authored
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.
1 parent 9b7734e commit 16a93c9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/proxy/http/remap/PluginDso.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,18 @@ PluginDso::LoadedPlugins::add(PluginDso *plugin)
329329
void
330330
PluginDso::LoadedPlugins::remove(PluginDso *plugin)
331331
{
332-
SCOPED_MUTEX_LOCK(lock, _mutex, this_ethread());
332+
EThread *ethread = this_ethread();
333+
if (ethread == nullptr) {
334+
// During static destruction, EThreads are gone. Just delete directly.
335+
_list.erase(plugin);
336+
delete plugin;
337+
return;
338+
}
339+
340+
SCOPED_MUTEX_LOCK(lock, _mutex, ethread);
333341

334342
_list.erase(plugin);
335-
this_ethread()->schedule_imm(new DeleterContinuation<PluginDso>(plugin));
343+
ethread->schedule_imm(new DeleterContinuation<PluginDso>(plugin));
336344
}
337345

338346
/* check if need to reload the plugin DSO

0 commit comments

Comments
 (0)