diff --git a/source/server/server.cc b/source/server/server.cc index 214f9d045938..0e238f9825d8 100644 --- a/source/server/server.cc +++ b/source/server/server.cc @@ -246,6 +246,14 @@ void InstanceImpl::flushStatsInternal() { bool InstanceImpl::healthCheckFailed() { return !live_.load(); } +ProcessContextOptRef InstanceImpl::processContext() { + if (process_context_ == nullptr) { + return absl::nullopt; + } + + return *process_context_; +} + namespace { // Loads a bootstrap object, potentially at a specific version (upgrading if necessary). void loadBootstrap(absl::optional bootstrap_version, diff --git a/source/server/server.h b/source/server/server.h index 1c06562b5a0e..0409b9db529b 100644 --- a/source/server/server.h +++ b/source/server/server.h @@ -251,7 +251,7 @@ class InstanceImpl final : Logger::Loggable, Stats::Store& stats() override { return stats_store_; } Grpc::Context& grpcContext() override { return grpc_context_; } Http::Context& httpContext() override { return http_context_; } - ProcessContextOptRef processContext() override { return *process_context_; } + ProcessContextOptRef processContext() override; ThreadLocal::Instance& threadLocal() override { return thread_local_; } const LocalInfo::LocalInfo& localInfo() const override { return *local_info_; } TimeSource& timeSource() override { return time_source_; } diff --git a/test/server/server_test.cc b/test/server/server_test.cc index aa097fc787cf..1db932a7c8c4 100644 --- a/test/server/server_test.cc +++ b/test/server/server_test.cc @@ -1411,6 +1411,16 @@ TEST_P(ServerInstanceImplTest, DisabledExtension) { ASSERT_TRUE(disabled_filter_found); } +TEST_P(ServerInstanceImplTest, NullProcessContextTest) { + // These are already the defaults. Repeated here for clarity. + process_object_ = nullptr; + process_context_ = nullptr; + + initialize("test/server/test_data/server/empty_bootstrap.yaml"); + ProcessContextOptRef context = server_->processContext(); + EXPECT_FALSE(context.has_value()); +} + } // namespace } // namespace Server } // namespace Envoy