Skip to content
Closed
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
22 changes: 14 additions & 8 deletions source/common/upstream/health_checker_base_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ HealthCheckerImplBase::HealthCheckerImplBase(const Cluster& cluster,
}

HealthCheckerImplBase::~HealthCheckerImplBase() {
// Make sure that any sessions that were deferred deleted are cleared before we destruct.
dispatcher_.clearDeferredDeleteList();
// ASSERTs inside the session destructor check to make sure we have been previously deferred
// deleted. Unify that logic here before actual destruction happens.
for (auto& session : active_sessions_) {
session.second->onDeferredDeleteBase();
}
}

void HealthCheckerImplBase::decHealthy() {
Expand Down Expand Up @@ -226,19 +229,22 @@ HealthCheckerImplBase::ActiveHealthCheckSession::ActiveHealthCheckSession(
}

HealthCheckerImplBase::ActiveHealthCheckSession::~ActiveHealthCheckSession() {
if (!host_->healthFlagGet(Host::HealthFlag::FAILED_ACTIVE_HC)) {
parent_.decHealthy();
}
if (host_->healthFlagGet(Host::HealthFlag::DEGRADED_ACTIVE_HC)) {
parent_.decDegraded();
}
// Make sure onDeferredDeleteBase() has been called. We should not reference our parent at this
// point since we may have been deferred deleted.
ASSERT(interval_timer_ == nullptr && timeout_timer_ == nullptr);
}

void HealthCheckerImplBase::ActiveHealthCheckSession::onDeferredDeleteBase() {
// The session is about to be deferred deleted. Make sure all timers are gone and any
// implementation specific state is destroyed.
interval_timer_.reset();
timeout_timer_.reset();
if (!host_->healthFlagGet(Host::HealthFlag::FAILED_ACTIVE_HC)) {
parent_.decHealthy();
}
if (host_->healthFlagGet(Host::HealthFlag::DEGRADED_ACTIVE_HC)) {
parent_.decDegraded();
}
onDeferredDelete();
}

Expand Down
3 changes: 0 additions & 3 deletions source/common/upstream/health_checker_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ HttpHealthCheckerImpl::HttpActiveHealthCheckSession::HttpActiveHealthCheckSessio
local_address_(std::make_shared<Network::Address::Ipv4Instance>("127.0.0.1")) {}

HttpHealthCheckerImpl::HttpActiveHealthCheckSession::~HttpActiveHealthCheckSession() {
onDeferredDelete();
ASSERT(client_ == nullptr);
}

Expand Down Expand Up @@ -379,7 +378,6 @@ TcpHealthCheckerImpl::TcpHealthCheckerImpl(const Cluster& cluster,
receive_bytes_(TcpHealthCheckMatcher::loadProtoBytes(config.tcp_health_check().receive())) {}

TcpHealthCheckerImpl::TcpActiveHealthCheckSession::~TcpActiveHealthCheckSession() {
onDeferredDelete();
ASSERT(client_ == nullptr);
}

Expand Down Expand Up @@ -487,7 +485,6 @@ GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::GrpcActiveHealthCheckSessio
: ActiveHealthCheckSession(parent, host), parent_(parent) {}

GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::~GrpcActiveHealthCheckSession() {
onDeferredDelete();
ASSERT(client_ == nullptr);
}

Expand Down
1 change: 0 additions & 1 deletion source/extensions/health_checkers/redis/redis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ RedisHealthChecker::RedisActiveHealthCheckSession::RedisActiveHealthCheckSession
: ActiveHealthCheckSession(parent, host), parent_(parent) {}

RedisHealthChecker::RedisActiveHealthCheckSession::~RedisActiveHealthCheckSession() {
onDeferredDelete();
ASSERT(current_request_ == nullptr);
ASSERT(client_ == nullptr);
}
Expand Down
1 change: 0 additions & 1 deletion test/common/upstream/health_checker_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ TEST(HealthCheckerFactoryTest, CreateGrpc) {
Event::MockDispatcher dispatcher;
AccessLog::MockAccessLogManager log_manager;

EXPECT_CALL(dispatcher, clearDeferredDeleteList());
EXPECT_NE(nullptr, dynamic_cast<GrpcHealthCheckerImpl*>(
HealthCheckerFactory::create(createGrpcHealthCheckConfig(), cluster,
runtime, random, dispatcher, log_manager)
Expand Down
1 change: 0 additions & 1 deletion test/extensions/health_checkers/redis/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ TEST(HealthCheckerFactoryTest, CreateRedisViaUpstreamHealthCheckerFactory) {
Event::MockDispatcher dispatcher;
AccessLog::MockAccessLogManager log_manager;

EXPECT_CALL(dispatcher, clearDeferredDeleteList());
EXPECT_NE(nullptr, dynamic_cast<CustomRedisHealthChecker*>(
Upstream::HealthCheckerFactory::create(
Upstream::parseHealthCheckFromV2Yaml(yaml), cluster, runtime, random,
Expand Down