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 fec62f1b1cb73e682f6bebe88cd900760f6d43f0
Author: Chris McFarlen <[email protected]>
AuthorDate: Mon Mar 30 17:31:53 2026 -0500

    hrw: Refix loading geodb files (#13025)
    
    * Restore old behavior to only call geo init with a geopath
    
    * Split geo init from plugin init
    
    (cherry picked from commit 5444571f415bf7318fce2f605cdf024bde5c211f)
---
 plugins/header_rewrite/header_rewrite.cc | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/plugins/header_rewrite/header_rewrite.cc 
b/plugins/header_rewrite/header_rewrite.cc
index d1f4ad16ed..cb4e971727 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -45,15 +45,20 @@ const char PLUGIN_NAME_DBG[] = "dbg_header_rewrite";
 DbgCtl dbg_ctl{PLUGIN_NAME_DBG};
 DbgCtl pi_dbg_ctl{PLUGIN_NAME};
 
-std::once_flag initHRWLibs;
+std::once_flag initGeoLibs;
+std::once_flag initPlugin;
 PluginFactory  plugin_factory;
 } // namespace header_rewrite_ns
 
 static void
-initHRWLibraries(const std::string &dbPath)
+initPluginFactory()
 {
   
header_rewrite_ns::plugin_factory.setRuntimeDir(RecConfigReadRuntimeDir()).addSearchDir(RecConfigReadPluginDir());
+}
 
+static void
+initGeoLibraries(const std::string &dbPath)
+{
   if (dbPath.empty()) {
     return;
   }
@@ -421,7 +426,8 @@ TSPluginInit(int argc, const char *argv[])
 
   Dbg(pi_dbg_ctl, "Global geo db %s", geoDBpath.c_str());
 
-  std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); });
+  std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLibraries(geoDBpath); });
+  std::call_once(initPlugin, initPluginFactory);
 
   // Parse the global config file(s). All rules are just appended
   // to the "global" Rules configuration.
@@ -501,17 +507,19 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, 
char * /* errbuf ATS_UNUSE
     }
   }
 
-  if (!geoDBpath.empty() && !geoDBpath.starts_with('/')) {
-    geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
-  }
-
   if (!geoDBpath.empty()) {
+    if (!geoDBpath.starts_with('/')) {
+      geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
+    }
     Dbg(pi_dbg_ctl, "Remap geo db %s", geoDBpath.c_str());
+
+    // This MUST be called only if the geoDBpath is set.  If called without a 
geoDBPath (i.e. outside of this if) then
+    // NO hrw remap rule can load a mmdb file.
+    // The call_once applies to every remap instance as its a plugin global
+    std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLibraries(geoDBpath); 
});
   }
 
-  // Always initialize the plugin factory, even if no geo DB is specified. This
-  // is needed for run-plugin to work with relative paths.
-  std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); });
+  std::call_once(initPlugin, initPluginFactory);
 
   RulesConfig *conf = new RulesConfig;
 

Reply via email to