diff --git a/src/envoy/http/jwt_auth/auth_store.h b/src/envoy/http/jwt_auth/auth_store.h index 2410929e4eb..3bb66315882 100644 --- a/src/envoy/http/jwt_auth/auth_store.h +++ b/src/envoy/http/jwt_auth/auth_store.h @@ -66,13 +66,16 @@ class JwtAuthStoreFactory : public Logger::Loggable { JwtAuthStoreFactory(const ::istio::envoy::config::filter::http::jwt_auth:: v2alpha1::JwtAuthentication& config, Server::Configuration::FactoryContext& context) - : config_(config), tls_(context.threadLocal().allocateSlot()) { - tls_->set( - [this](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr { - return std::make_shared(config_); - }); + : config_( + std::make_shared<::istio::envoy::config::filter::http::jwt_auth:: + v2alpha1::JwtAuthentication>(config)), + tls_(context.threadLocal().allocateSlot()) { + tls_->set([config = this->config_](Event::Dispatcher&) + -> ThreadLocal::ThreadLocalObjectSharedPtr { + return std::make_shared(*config); + }); ENVOY_LOG(debug, "Loaded JwtAuthConfig: {}", - MessageUtil::getJsonStringFromMessage(config_, true)); + MessageUtil::getJsonStringFromMessage(*config_, true)); } // Get per-thread auth store object. @@ -80,7 +83,8 @@ class JwtAuthStoreFactory : public Logger::Loggable { private: // The auth config. - ::istio::envoy::config::filter::http::jwt_auth::v2alpha1::JwtAuthentication + std::shared_ptr<::istio::envoy::config::filter::http::jwt_auth::v2alpha1:: + JwtAuthentication> config_; // Thread local slot to store per-thread auth store ThreadLocal::SlotPtr tls_; diff --git a/src/envoy/http/mixer/control_factory.h b/src/envoy/http/mixer/control_factory.h index 83ff0e84ee9..04b3e3d09ec 100644 --- a/src/envoy/http/mixer/control_factory.h +++ b/src/envoy/http/mixer/control_factory.h @@ -45,19 +45,19 @@ class ControlFactory : public Logger::Loggable { Stats::Scope& scope = context.scope(); const LocalInfo::LocalInfo& local_info = context.localInfo(); - tls_->set( - [this, &cm, &random, &scope, &local_info](Event::Dispatcher& dispatcher) - -> ThreadLocal::ThreadLocalObjectSharedPtr { - return std::make_shared(*config_, cm, dispatcher, random, - scope, stats_, local_info); - }); + tls_->set([config = this->config_, &stats = this->stats_, &cm, &random, + &scope, &local_info](Event::Dispatcher& dispatcher) + -> ThreadLocal::ThreadLocalObjectSharedPtr { + return std::make_shared(*config, cm, dispatcher, random, scope, + stats, local_info); + }); } Control& control() { return tls_->getTyped(); } private: // Own the config object. - std::unique_ptr config_; + std::shared_ptr config_; // Thread local slot. ThreadLocal::SlotPtr tls_; // This stats object. diff --git a/src/envoy/tcp/mixer/control_factory.h b/src/envoy/tcp/mixer/control_factory.h index a33c08151c6..f5ba66dfec3 100644 --- a/src/envoy/tcp/mixer/control_factory.h +++ b/src/envoy/tcp/mixer/control_factory.h @@ -41,11 +41,12 @@ class ControlFactory : public Logger::Loggable { Stats::Scope& scope = context.scope(); const LocalInfo::LocalInfo& local_info = context.localInfo(); - tls_->set([this, &random, &scope, + tls_->set([config = this->config_, &cm = this->cm_, uuid = this->uuid_, + &stats = this->stats_, &random, &scope, &local_info](Event::Dispatcher& dispatcher) -> ThreadLocal::ThreadLocalObjectSharedPtr { return ThreadLocal::ThreadLocalObjectSharedPtr(new Control( - *config_, cm_, dispatcher, random, scope, stats_, uuid_, local_info)); + *config, cm, dispatcher, random, scope, stats, uuid, local_info)); }); } @@ -60,7 +61,7 @@ class ControlFactory : public Logger::Loggable { } // The config object - std::unique_ptr config_; + std::shared_ptr config_; // The cluster manager Upstream::ClusterManager& cm_; // the thread local slots