Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Return nullopt when process_context is nullptr #14181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions source/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> bootstrap_version,
Expand Down
2 changes: 1 addition & 1 deletion source/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class InstanceImpl final : Logger::Loggable<Logger::Id::main>,
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_; }
Expand Down
10 changes: 10 additions & 0 deletions test/server/server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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