@@ -613,10 +613,29 @@ int main(int argc, const char* argv[])
613613 Owned<IPropertyTreeIterator> iter = daFileSrv->getElements (" Instance" );
614614 ForEach (*iter)
615615 {
616- IpAddress instanceIP (iter->query ().queryProp (" @netAddress" ));
616+ const char *instanceAddr = iter->query ().queryProp (" @netAddress" );
617+ if (isEmptyString (instanceAddr))
618+ continue ;
619+ IpAddress instanceIP (instanceAddr);
617620 if (instanceIP.ipequals (queryHostIP ()))
618- dafileSrvInstance = &iter->query ();
621+ {
622+ _dafileSrvInstance.set (&iter->query ());
623+ dafileSrvInstance = _dafileSrvInstance;
624+ break ;
625+ }
626+ }
627+ // If host IP matching fails (e.g. localhost-vs-interface differences),
628+ // fall back to first configured instance instead of dereferencing null.
629+ if (!dafileSrvInstance)
630+ {
631+ IPropertyTree *firstInstance = daFileSrv->queryPropTree (" Instance[1]" );
632+ if (firstInstance)
633+ {
634+ _dafileSrvInstance.set (firstInstance);
635+ dafileSrvInstance = _dafileSrvInstance;
636+ }
619637 }
638+
620639 if (dafileSrvInstance)
621640 {
622641 // check if there's a DaFileSrvGroup
@@ -628,24 +647,27 @@ int main(int argc, const char* argv[])
628647 if (daFileSrvGroup)
629648 {
630649 // create a copy of the group settings and merge in (overwrite) with the instance settings, i.e. any group settings become defaults
631- _dafileSrvInstance.setown (createPTreeFromIPT (daFileSrvGroup));
632- synchronizePTree (_dafileSrvInstance, dafileSrvInstance, false , false );
650+ Owned<IPropertyTree> mergedInstance;
651+ mergedInstance.setown (createPTreeFromIPT (daFileSrvGroup));
652+ synchronizePTree (mergedInstance, dafileSrvInstance, false , false );
653+ _dafileSrvInstance.setown (mergedInstance.getClear ());
633654 dafileSrvInstance = _dafileSrvInstance;
634655 }
635656 }
636657 }
637658
638659 // merge in bare-metal dafilesrv instance expert settings
639660 IPropertyTree *instanceExpert = nullptr ;
640- instanceExpert = dafileSrvInstance->queryPropTree (" expert" );
661+ if (dafileSrvInstance)
662+ instanceExpert = dafileSrvInstance->queryPropTree (" expert" );
641663 if (instanceExpert)
642664 synchronizePTree (expert, instanceExpert, false , true );
643665 }
644666
645667 // update config and hook callback with dafilesrv expert PTree
646668 replaceComponentConfig (newConfig, getGlobalConfigSP ());
647669
648- // bare-metal gets it's certificate info. from environment at the moment, 'keyPairInfo' not used in containerized mode
670+ // bare-metal gets its certificate info. from environment at the moment, 'keyPairInfo' not used in containerized mode
649671 keyPairInfo.set (env->queryPropTree (" EnvSettings/Keys" ));
650672 }
651673
0 commit comments