@@ -19,10 +19,13 @@ int64_t currentUnusedCapacity(const std::list<ActiveClientPtr>& connecting_clien
19
19
}
20
20
} // namespace
21
21
22
+ std::string ConnPoolImplBase::dumpState () const { return fmt::format (" State: {}" , *this ); }
23
+
22
24
void ConnPoolImplBase::assertCapacityCountsAreCorrect () {
23
25
SLOW_ASSERT (static_cast <int64_t >(connecting_stream_capacity_) ==
24
- currentUnusedCapacity (connecting_clients_) +
25
- currentUnusedCapacity (early_data_clients_));
26
+ currentUnusedCapacity (connecting_clients_) +
27
+ currentUnusedCapacity (early_data_clients_),
28
+ dumpState ());
26
29
27
30
// Note: must include `busy_clients_` because they can have negative current unused capacity,
28
31
// which is included in `connecting_and_connected_stream_capacity_`.
@@ -31,10 +34,18 @@ void ConnPoolImplBase::assertCapacityCountsAreCorrect() {
31
34
(static_cast <int64_t >(connecting_stream_capacity_) +
32
35
currentUnusedCapacity (ready_clients_) + currentUnusedCapacity (busy_clients_)),
33
36
fmt::format (
34
- " connecting_and_connected_stream_capacity_ {}, connecting_stream_capacity_ {}, "
35
- " currentUnusedCapacity(ready_clients_) {}, currentUnusedCapacity(busy_clients_) {}" ,
36
- connecting_and_connected_stream_capacity_, connecting_stream_capacity_,
37
- currentUnusedCapacity (ready_clients_), currentUnusedCapacity (busy_clients_)));
37
+ " {} currentUnusedCapacity(ready_clients_) {}, currentUnusedCapacity(busy_clients_) {}" ,
38
+ *this , currentUnusedCapacity (ready_clients_), currentUnusedCapacity (busy_clients_)));
39
+
40
+ SLOW_ASSERT (currentUnusedCapacity (busy_clients_) <= 0 , dumpState ());
41
+
42
+ if (ready_clients_.empty ()) {
43
+ ASSERT ((connecting_and_connected_stream_capacity_ - connecting_stream_capacity_) <= 0 ,
44
+ dumpState ());
45
+ } else {
46
+ ASSERT ((connecting_and_connected_stream_capacity_ - connecting_stream_capacity_) > 0 ,
47
+ dumpState ());
48
+ }
38
49
}
39
50
40
51
ConnPoolImplBase::ConnPoolImplBase (
@@ -47,16 +58,16 @@ ConnPoolImplBase::ConnPoolImplBase(
47
58
upstream_ready_cb_(dispatcher_.createSchedulableCallback([this ]() { onUpstreamReady (); })) {}
48
59
49
60
ConnPoolImplBase::~ConnPoolImplBase () {
50
- ASSERT (isIdleImpl ());
51
- ASSERT (connecting_stream_capacity_ == 0 );
52
- ASSERT (connecting_and_connected_stream_capacity_ == 0 );
61
+ ASSERT (isIdleImpl (), dumpState () );
62
+ ASSERT (connecting_stream_capacity_ == 0 , dumpState () );
63
+ ASSERT (connecting_and_connected_stream_capacity_ == 0 , dumpState () );
53
64
}
54
65
55
66
void ConnPoolImplBase::deleteIsPendingImpl () {
56
67
deferred_deleting_ = true ;
57
- ASSERT (isIdleImpl ());
58
- ASSERT (connecting_stream_capacity_ == 0 );
59
- ASSERT (connecting_and_connected_stream_capacity_ == 0 );
68
+ ASSERT (isIdleImpl (), dumpState () );
69
+ ASSERT (connecting_stream_capacity_ == 0 , dumpState () );
70
+ ASSERT (connecting_and_connected_stream_capacity_ == 0 , dumpState () );
60
71
}
61
72
62
73
void ConnPoolImplBase::destructAllConnections () {
@@ -156,7 +167,8 @@ ConnPoolImplBase::ConnectionResult ConnPoolImplBase::tryCreateNewConnections() {
156
167
break ;
157
168
}
158
169
}
159
- ASSERT (!is_draining_for_deletion_ || result != ConnectionResult::CreatedNewConnection);
170
+ ASSERT (!is_draining_for_deletion_ || result != ConnectionResult::CreatedNewConnection,
171
+ dumpState ());
160
172
return result;
161
173
}
162
174
@@ -184,9 +196,10 @@ ConnPoolImplBase::tryCreateNewConnection(float global_preconnect_ratio) {
184
196
ENVOY_LOG (trace, " connection creation failed" );
185
197
return ConnectionResult::FailedToCreateConnection;
186
198
}
187
- ASSERT (client->state () == ActiveClient::State::Connecting);
199
+ ASSERT (client->state () == ActiveClient::State::Connecting, dumpState () );
188
200
ASSERT (std::numeric_limits<uint64_t >::max () - connecting_stream_capacity_ >=
189
- static_cast <uint64_t >(client->currentUnusedCapacity ()));
201
+ static_cast <uint64_t >(client->currentUnusedCapacity ()),
202
+ dumpState ());
190
203
ASSERT (client->real_host_description_ );
191
204
// Increase the connecting capacity to reflect the streams this connection can serve.
192
205
incrConnectingAndConnectedStreamCapacity (client->currentUnusedCapacity (), *client);
@@ -202,7 +215,7 @@ ConnPoolImplBase::tryCreateNewConnection(float global_preconnect_ratio) {
202
215
203
216
void ConnPoolImplBase::attachStreamToClient (Envoy::ConnectionPool::ActiveClient& client,
204
217
AttachContext& context) {
205
- ASSERT (client.readyForStream ());
218
+ ASSERT (client.readyForStream (), dumpState () );
206
219
207
220
Upstream::ClusterTrafficStats& traffic_stats = *host_->cluster ().trafficStats ();
208
221
if (client.state () == Envoy::ConnectionPool::ActiveClient::State::ReadyForEarlyData) {
@@ -252,7 +265,7 @@ void ConnPoolImplBase::onStreamClosed(Envoy::ConnectionPool::ActiveClient& clien
252
265
ENVOY_CONN_LOG (
253
266
debug, " destroying stream: {} active remaining, readyForStream {}, currentUnusedCapacity {}" ,
254
267
client, client.numActiveStreams (), client.readyForStream (), client.currentUnusedCapacity ());
255
- ASSERT (num_active_streams_ > 0 );
268
+ ASSERT (num_active_streams_ > 0 , dumpState () );
256
269
state_.decrActiveStreams (1 );
257
270
num_active_streams_--;
258
271
host_->stats ().rq_active_ .dec ();
@@ -265,9 +278,9 @@ void ConnPoolImplBase::onStreamClosed(Envoy::ConnectionPool::ActiveClient& clien
265
278
bool limited_by_concurrency =
266
279
client.remaining_streams_ > client.concurrent_stream_limit_ - client.numActiveStreams () - 1 ;
267
280
// The capacity calculated by concurrency could be negative if a SETTINGS frame lowered the
268
- // number of allowed streams. In this case, effective client capacity was still limited by
269
- // concurrency, compare client.concurrent_stream_limit_ and client.numActiveStreams() directly
270
- // to avoid overflow.
281
+ // number of allowed streams. In this case, connecting_and_connected_stream_capacity_ can be
282
+ // negative, and effective client capacity was still limited by concurrency. Compare
283
+ // client.concurrent_stream_limit_ and client.numActiveStreams() directly to avoid overflow.
271
284
bool negative_capacity = client.concurrent_stream_limit_ < client.numActiveStreams () + 1 ;
272
285
if (negative_capacity || limited_by_concurrency) {
273
286
incrConnectingAndConnectedStreamCapacity (1 , client);
@@ -293,8 +306,8 @@ void ConnPoolImplBase::onStreamClosed(Envoy::ConnectionPool::ActiveClient& clien
293
306
294
307
ConnectionPool::Cancellable* ConnPoolImplBase::newStreamImpl (AttachContext& context,
295
308
bool can_send_early_data) {
296
- ASSERT (!is_draining_for_deletion_);
297
- ASSERT (!deferred_deleting_);
309
+ ASSERT (!is_draining_for_deletion_, dumpState () );
310
+ ASSERT (!deferred_deleting_, dumpState () );
298
311
assertCapacityCountsAreCorrect ();
299
312
300
313
if (!ready_clients_.empty ()) {
@@ -351,7 +364,7 @@ ConnectionPool::Cancellable* ConnPoolImplBase::newStreamImpl(AttachContext& cont
351
364
}
352
365
353
366
bool ConnPoolImplBase::maybePreconnectImpl (float global_preconnect_ratio) {
354
- ASSERT (!deferred_deleting_);
367
+ ASSERT (!deferred_deleting_, dumpState () );
355
368
return tryCreateNewConnection (global_preconnect_ratio) == ConnectionResult::CreatedNewConnection;
356
369
}
357
370
@@ -440,7 +453,7 @@ void ConnPoolImplBase::closeIdleConnectionsForDrainingPool() {
440
453
441
454
void ConnPoolImplBase::drainClients (std::list<ActiveClientPtr>& clients) {
442
455
while (!clients.empty ()) {
443
- ASSERT (clients.front ()->numActiveStreams () > 0u );
456
+ ASSERT (clients.front ()->numActiveStreams () > 0u , dumpState () );
444
457
ENVOY_LOG_EVENT (
445
458
debug, " draining_non_idle_client" , " draining {} client {} for cluster {}" ,
446
459
(clients.front ()->state () == ActiveClient::State::Ready ? " ready" : " early data" ),
@@ -469,7 +482,7 @@ void ConnPoolImplBase::drainConnectionsImpl(DrainBehavior drain_behavior) {
469
482
470
483
// Changing busy_clients_ to Draining does not move them between lists,
471
484
// so use a for-loop since the list is not mutated.
472
- ASSERT (&owningList (ActiveClient::State::Draining) == &busy_clients_);
485
+ ASSERT (&owningList (ActiveClient::State::Draining) == &busy_clients_, dumpState () );
473
486
for (auto & busy_client : busy_clients_) {
474
487
if (busy_client->state () == ActiveClient::State::Draining) {
475
488
continue ;
@@ -609,7 +622,7 @@ void ConnPoolImplBase::onConnectionEvent(ActiveClient& client, absl::string_view
609
622
client.connect_timer_ ->disableTimer ();
610
623
client.connect_timer_ .reset ();
611
624
612
- ASSERT (connecting_stream_capacity_ >= client.currentUnusedCapacity ());
625
+ ASSERT (connecting_stream_capacity_ >= client.currentUnusedCapacity (), dumpState () );
613
626
connecting_stream_capacity_ -= client.currentUnusedCapacity ();
614
627
client.has_handshake_completed_ = true ;
615
628
client.conn_connect_ms_ ->complete ();
@@ -690,7 +703,7 @@ void ConnPoolImplBase::purgePendingStreams(
690
703
691
704
bool ConnPoolImplBase::connectingConnectionIsExcess (const ActiveClient& client) const {
692
705
ASSERT (!client.hasHandshakeCompleted ());
693
- ASSERT (connecting_stream_capacity_ >= client.currentUnusedCapacity ());
706
+ ASSERT (connecting_stream_capacity_ >= client.currentUnusedCapacity (), dumpState () );
694
707
// If perUpstreamPreconnectRatio is one, this simplifies to checking if there would still be
695
708
// sufficient connecting stream capacity to serve all pending streams if the most recent client
696
709
// were removed from the picture.
@@ -747,7 +760,7 @@ void ConnPoolImplBase::decrConnectingAndConnectedStreamCapacity(uint32_t delta,
747
760
if (!client.hasHandshakeCompleted ()) {
748
761
// If still doing handshake, it is contributing to the local connecting stream capacity. Update
749
762
// the capacity as well.
750
- ASSERT (connecting_stream_capacity_ >= delta);
763
+ ASSERT (connecting_stream_capacity_ >= delta, dumpState () );
751
764
connecting_stream_capacity_ -= delta;
752
765
}
753
766
}
0 commit comments