Skip to content
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
5 changes: 4 additions & 1 deletion source/common/conn_pool/conn_pool_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ float ConnPoolImplBase::perUpstreamPreconnectRatio() const {
}

ConnPoolImplBase::ConnectionResult ConnPoolImplBase::tryCreateNewConnections() {
ASSERT(!is_draining_for_deletion_);
ConnPoolImplBase::ConnectionResult result;
// Somewhat arbitrarily cap the number of connections preconnected due to new
// incoming connections. The preconnect ratio is capped at 3, so in steady
Expand Down Expand Up @@ -462,7 +463,9 @@ void ConnPoolImplBase::onConnectionEvent(ActiveClient& client, absl::string_view
// if retry logic submits a new stream to the pool, we don't fail it inline.
purgePendingStreams(client.real_host_description_, failure_reason, reason);
// See if we should preconnect based on active connections.
tryCreateNewConnections();
if (!is_draining_for_deletion_) {
tryCreateNewConnections();
}
}

// We need to release our resourceManager() resources before checking below for
Expand Down
26 changes: 26 additions & 0 deletions test/integration/cds_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,32 @@ TEST_P(CdsIntegrationTest, CdsClusterUpDownUp) {
cleanupUpstreamAndDownstream();
}

// Make sure that clusters won't create new connections on teardown.
TEST_P(CdsIntegrationTest, CdsClusterTeardownWhileConnecting) {
initialize();
test_server_->waitForCounterGe("cluster_manager.cluster_added", 1);

// Make the upstreams stop working, to ensure the connection was not
// established.
fake_upstreams_[1]->dispatcher()->exit();
fake_upstreams_[2]->dispatcher()->exit();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder = codec_client_->startRequest(Http::TestRequestHeaderMapImpl{
{":method", "GET"}, {":path", "/cluster1"}, {":scheme", "http"}, {":authority", "host"}});

// Tell Envoy that cluster_1 is gone.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "55", {}, {}, {}));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster, {}, {},
{ClusterName1}, "42");
// We can continue the test once we're sure that Envoy's ClusterManager has made use of
// the DiscoveryResponse that says cluster_1 is gone.
test_server_->waitForCounterGe("cluster_manager.cluster_removed", 1);
codec_client_->sendReset(encoder_decoder.first);
cleanupUpstreamAndDownstream();
// Make sure there was only one connection attempt.
EXPECT_LE(test_server_->counter("cluster.cluster_1.upstream_cx_total")->value(), 1);
}

// Test the fast addition and removal of clusters when they use ThreadAwareLb.
TEST_P(CdsIntegrationTest, CdsClusterWithThreadAwareLbCycleUpDownUp) {
// Calls our initialize(), which includes establishing a listener, route, and cluster.
Expand Down
2 changes: 1 addition & 1 deletion tools/base/envoy_python.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_python//python:defs.bzl", "py_binary")
load("@base_pip3//:requirements.bzl", base_entry_point = "entry_point")

def envoy_py_test(name, package, visibility, envoy_prefix = "@envoy"):
Expand Down