Skip to content

Commit 5444571

Browse files
authored
hrw: Refix loading geodb files (#13025)
* Restore old behavior to only call geo init with a geopath * Split geo init from plugin init
1 parent 064014b commit 5444571

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

plugins/header_rewrite/header_rewrite.cc

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@
4141
// Debugs
4242
namespace header_rewrite_ns
4343
{
44-
std::once_flag initHRWLibs;
44+
std::once_flag initGeoLibs;
45+
std::once_flag initPlugin;
4546
PluginFactory plugin_factory;
4647
} // namespace header_rewrite_ns
4748

4849
static void
49-
initHRWLibraries(const std::string &dbPath)
50+
initPluginFactory()
5051
{
5152
header_rewrite_ns::plugin_factory.setRuntimeDir(RecConfigReadRuntimeDir()).addSearchDir(RecConfigReadPluginDir());
53+
}
5254

55+
static void
56+
initGeoLibraries(const std::string &dbPath)
57+
{
5358
if (dbPath.empty()) {
5459
return;
5560
}
@@ -597,7 +602,8 @@ TSPluginInit(int argc, const char *argv[])
597602

598603
Dbg(pi_dbg_ctl, "Global geo db %s", geoDBpath.c_str());
599604

600-
std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); });
605+
std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLibraries(geoDBpath); });
606+
std::call_once(initPlugin, initPluginFactory);
601607

602608
// Parse the global config file(s). All rules are just appended
603609
// to the "global" Rules configuration.
@@ -705,17 +711,19 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
705711
}
706712
}
707713

708-
if (!geoDBpath.empty() && !geoDBpath.starts_with('/')) {
709-
geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
710-
}
711-
712714
if (!geoDBpath.empty()) {
715+
if (!geoDBpath.starts_with('/')) {
716+
geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
717+
}
713718
Dbg(pi_dbg_ctl, "Remap geo db %s", geoDBpath.c_str());
719+
720+
// This MUST be called only if the geoDBpath is set. If called without a geoDBPath (i.e. outside of this if) then
721+
// NO hrw remap rule can load a mmdb file.
722+
// The call_once applies to every remap instance as its a plugin global
723+
std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLibraries(geoDBpath); });
714724
}
715725

716-
// Always initialize the plugin factory, even if no geo DB is specified. This
717-
// is needed for run-plugin to work with relative paths.
718-
std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); });
726+
std::call_once(initPlugin, initPluginFactory);
719727

720728
auto *conf = new RulesConfig(timezone, inboundIpSource);
721729

0 commit comments

Comments
 (0)