Skip to content

Commit ede8074

Browse files
authored
xds: update trace log to only print non-nullptr exceptions (envoyproxy#44026)
Commit Message: xds: update trace log to only print non-nullptr exceptions Additional Description: Upon an xDS-error, trace-logs output the exception details. However there are a few cases where an exception is created with nullptr passed. This PR introduces defensive coding in the cases where the exception details are printed out to the trace logs. Risk Level: low - only trace-logs are impacted Testing: Added unit test to avoid regression in this case. Docs Changes: N/A Release Notes: N/A - not user facing (trace logs) Platform Specific Features: N/A --------- Signed-off-by: Adi Suissa-Peleg <adip@google.com>
1 parent a2a52d3 commit ede8074

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

source/common/upstream/od_cds_api_impl.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "source/common/upstream/od_cds_api_impl.h"
22

33
#include "source/common/common/assert.h"
4+
#include "source/common/common/enum_to_int.h"
45
#include "source/common/grpc/common.h"
56

67
#include "absl/strings/str_join.h"
@@ -264,9 +265,12 @@ class XdstpOdCdsApiImpl::XdstpOdcdsSubscriptionsManager : public Singleton::Inst
264265
}
265266
void onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason reason,
266267
const EnvoyException* e) override {
267-
ASSERT(reason != Envoy::Config::ConfigUpdateFailureReason::ConnectionFailure);
268-
ENVOY_LOG(trace, "ODCDS-manager: error while fetching a single resource {}: {}",
269-
resource_name_, e->what());
268+
// The passed exception object is null iff the error reason is
269+
// Envoy::Config::ConfigUpdateFailureReason::ConnectionFailure or
270+
// Envoy::Config::ConfigUpdateFailureReason::FetchTimedout.
271+
ENVOY_LOG(
272+
trace, "ODCDS-manager: error while fetching a single resource {}: (reason = {}), {}",
273+
resource_name_, enumToInt(reason), e == nullptr ? "exception not provided" : e->what());
270274
// If the resource wasn't previously updated, this sends a notification that it was removed,
271275
// so if there are any resources waiting for this one, they can proceed.
272276
if (!resource_was_updated_) {

test/common/upstream/xdstp_od_cds_api_impl_test.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ TEST_F(XdstpOdCdsApiImplTest, SubscriptionFailure) {
182182
&e);
183183
}
184184

185+
// Tests that a config update failure with a null exception pointer is handled correctly.
186+
TEST_F(XdstpOdCdsApiImplTest, SubscriptionFailureNullException) {
187+
InSequence s;
188+
189+
const std::string cluster_name = "fake_cluster";
190+
expectSingletonSubscription(cluster_name);
191+
odcds_->updateOnDemand(cluster_name);
192+
193+
ASSERT_NE(odcds_callbacks_, nullptr);
194+
195+
EXPECT_CALL(cm_, addOrUpdateCluster(_, _, _)).Times(0);
196+
EXPECT_CALL(notifier_, notifyMissingCluster(cluster_name));
197+
198+
odcds_callbacks_->onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason::UpdateRejected,
199+
nullptr);
200+
}
201+
185202
// Tests that an existing cluster is updated.
186203
TEST_F(XdstpOdCdsApiImplTest, ClusterUpdate) {
187204
InSequence s;

0 commit comments

Comments
 (0)