mutex_tracer_(options.mutexTracingEnabled() ? &Envoy::MutexTracerImpl::getOrCreateTracer()
// The ListenerManager's DestinationPortsMap contains FilterChainSharedPtrs. There is a rare race
// condition where one of these FilterChains contains an HttpConnectionManager, which contains an
// RdsRouteConfigSubscription is an Init::Target, ~RdsRouteConfigSubscription triggers a callback
void InstanceBase::drainListeners(OptRef<const Network::ExtraShutdownListenerOptions> options) {
void InstanceUtil::flushMetricsToSinks(const std::list<Stats::SinkPtr>& sinks, Stats::Store& store,
ENVOY_LOG(debug, "Envoy is not fully initialized, skipping histogram merge and flushing stats");
HotRestart::ServerStatsFromParent parent_stats = restarter_.mergeParentStatsIfAny(stats_store_);
registerCustomInlineHeadersFromBootstrap(const envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
RETURN_IF_NOT_OK(MessageUtil::loadFromFile(config_path, bootstrap, validation_visitor, api));
ENVOY_LOG(warn, "Failed to read file descriptor limit, error {}.", errorDetails(result.errno_));
absl::Status InstanceBase::initializeOrThrow(Network::Address::InstanceConstSharedPtr local_address,
for (const auto& ext : Envoy::Registry::FactoryCategoryRegistry::registeredFactories()) {
ENVOY_LOG(info, " {}: {}", ext.first, absl::StrJoin(ext.second->registeredNames(), ", "));
// do so. This must be set before any other code block references the HeaderValues ConstSingleton.
bootstrap_, messageValidationContext().staticValidationVisitor(), serverFactoryContext());
// Needs to happen as early as possible in the instantiation to preempt the objects that require
Stats::TagProducerImpl::createTagProducer(bootstrap_.stats_config(), options_.statsTags());
std::make_unique<Stats::HistogramSettingsImpl>(bootstrap_.stats_config(), server_contexts_));
const std::string server_compilation_settings_stats_prefix = "server.compilation_settings";
CompilationSettings::ServerCompilationSettingsStats{ALL_SERVER_COMPILATION_SETTINGS_STATS(
*bootstrap_.mutable_node()->mutable_user_agent_build_version() = VersionInfo::buildVersion();
for (const auto& ext : Envoy::Registry::FactoryCategoryRegistry::registeredFactories()) {
stats().symbolTable(), bootstrap_.node(), bootstrap_.node_context_params(), local_address,
auto admin_impl = std::make_shared<AdminImpl>(initial_config.admin().profilePath(), *this,
auto& factory = Config::Utility::getAndCheckFactory<Configuration::BootstrapExtensionFactory>(
listener_manager_factory = &Config::Utility::getAndCheckFactoryByName<ListenerManagerFactory>(
// 5. Secondary clusters (with endpoint assignments provisioned by xDS servers) are initialized.
// Please note: this order requires that RTDS is provisioned using a primary cluster. If RTDS is
// provisioned through ADS then ADS must use primary cluster as well. This invariant is enforced
admin_->startHttpListener(initial_config.admin().accessLogs(), initial_config.admin().address(),
std::make_unique<Extensions::TransportSockets::Tls::ContextManagerImpl>(server_contexts_);
xds_manager_ = std::make_unique<Config::XdsManagerImpl>(*dispatcher_, *api_, stats_store_,
// Some of the stat sinks may need dispatcher support so don't flush until the main loop starts.
main_thread_guard_dog_ = maybeCreateGuardDog("main_thread", config_.mainThreadWatchdogConfig());
if (Runtime::runtimeFeatureEnabled("envoy.restart_features.worker_threads_watchdog_fix")) {
absl::StatusOr<std::unique_ptr<Runtime::LoaderImpl>> loader = Runtime::LoaderImpl::create(
"limit in `envoy.resource_monitors.global_downstream_max_connections` resource monitor.");
// upstream clusters are initialized which may involve running the event loop. Note however that
// to guard against shutdown at two different levels since SIGTERM can come in once the run loop
const auto type_url = Config::getTypeUrl<envoy::config::route::v3::RouteConfiguration>();
RunHelper(*this, options_, *dispatcher_, xdsManager(), clusterManager(), access_log_manager_,
watchdog = main_thread_guard_dog_->createWatchDog(api_->threadFactory().currentThreadId(),
void InstanceBase::notifyCallbacksForStage(Stage stage, std::function<void()> completion_cb) {