Skip to content

Commit 5b9a855

Browse files
authored
conn pool: fixed a bug with mixed connection pool capacity (envoyproxy#39349)
Fixed an issue that could lead to too many connections when using :ref:`AutoHttpConfig <envoy_v3_api_msg_extensions.upstreams.http.v3.HttpProtocolOptions.AutoHttpConfig>` if the established connection is ``http/2`` and Envoy predicted it would have lower concurrent capacity. Signed-off-by: Greg Greenway <[email protected]>
1 parent 453e95a commit 5b9a855

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

changelogs/current.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ minor_behavior_changes:
3636
3737
bug_fixes:
3838
# *Changes expected to improve the state of the world and are unlikely to have negative effects*
39+
- area: conn_pool
40+
change: |
41+
Fixed an issue that could lead to too many connections when using
42+
:ref:`AutoHttpConfig <envoy_v3_api_msg_extensions.upstreams.http.v3.HttpProtocolOptions.AutoHttpConfig>` if the
43+
established connection is ``http/2`` and Envoy predicted it would have lower concurrent capacity.
3944
- area: conn_pool
4045
change: |
4146
Fixed an issue that could lead to insufficient connections for current pending requests. If a connection starts draining while it

source/common/http/mixed_conn_pool.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ void HttpConnPoolImplMixed::onConnected(Envoy::ConnectionPool::ActiveClient& cli
8686
// it to reflect any difference between the TCP stream limits and HTTP/2
8787
// stream limits.
8888
if (new_client->effectiveConcurrentStreamLimit() > old_effective_limit) {
89-
state_.incrConnectingAndConnectedStreamCapacity(new_client->effectiveConcurrentStreamLimit() -
90-
old_effective_limit);
89+
incrConnectingAndConnectedStreamCapacity(
90+
new_client->effectiveConcurrentStreamLimit() - old_effective_limit, client);
9191
}
9292
new_client->setState(ActiveClient::State::Connecting);
9393
LinkedList::moveIntoList(std::move(new_client), owningList(new_client->state()));

test/common/http/mixed_conn_pool_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ TEST_F(MixedConnPoolImplTest, HandshakeWithCachedLimit) {
114114
testAlpnHandshake({});
115115
}
116116

117+
// Test that increasing the limit upon connect, versus what was in the cache before connection,
118+
// works correctly.
119+
TEST_F(MixedConnPoolImplTest, HandshakeWithCachedLimitAndEffectiveIncrease) {
120+
expected_capacity_ = 1;
121+
122+
// This simulates a previous connection being http 1.
123+
EXPECT_CALL(mock_cache_, getConcurrentStreams(_)).WillOnce(Return(1));
124+
125+
// This makes the new connection http 2, which has more than 1 stream available.
126+
testAlpnHandshake(Protocol::Http2);
127+
}
128+
117129
TEST_F(MixedConnPoolImplTest, HandshakeWithCachedLimitCapped) {
118130
EXPECT_CALL(mock_cache_, getConcurrentStreams(_))
119131
.WillOnce(Return(std::numeric_limits<uint32_t>::max()));

0 commit comments

Comments
 (0)