diff --git a/source/common/http/conn_pool_grid.cc b/source/common/http/conn_pool_grid.cc index 18cf101e0a3e9..e41007825e01b 100644 --- a/source/common/http/conn_pool_grid.cc +++ b/source/common/http/conn_pool_grid.cc @@ -36,13 +36,14 @@ ConnectivityGrid::WrapperCallbacks::ConnectionAttemptCallbacks::ConnectionAttemp WrapperCallbacks& parent, PoolIterator it) : parent_(parent), pool_it_(it), cancellable_(nullptr) {} -bool ConnectivityGrid::WrapperCallbacks::ConnectionAttemptCallbacks::newStream() { +ConnectivityGrid::StreamCreationResult +ConnectivityGrid::WrapperCallbacks::ConnectionAttemptCallbacks::newStream() { auto* cancellable = pool().newStream(parent_.decoder_, *this); if (cancellable == nullptr) { - return true; + return StreamCreationResult::ImmediateResult; } cancellable_ = cancellable; - return false; + return StreamCreationResult::StreamCreationPending; } void ConnectivityGrid::WrapperCallbacks::ConnectionAttemptCallbacks::onPoolFailure( @@ -82,7 +83,7 @@ void ConnectivityGrid::WrapperCallbacks::deleteThis() { removeFromList(grid_.wrapped_callbacks_); } -bool ConnectivityGrid::WrapperCallbacks::newStream() { +ConnectivityGrid::StreamCreationResult ConnectivityGrid::WrapperCallbacks::newStream() { ENVOY_LOG(trace, "{} pool attempting to create a new stream to host '{}'.", describePool(**current_), grid_.host_->hostname()); auto attempt = std::make_unique(*this, current_); @@ -137,7 +138,10 @@ bool ConnectivityGrid::WrapperCallbacks::tryAnotherConnection() { // If there are no other pools to try, return false. return false; } - // Create a new connection attempt for the next pool. + // Create a new connection attempt for the next pool. If we reach this point + // return true regardless of if newStream resulted in an immediate result or + // an async call, as either way the attempt will result in success/failure + // callbacks. current_ = next_pool.value(); newStream(); return true; @@ -209,7 +213,7 @@ ConnectionPool::Cancellable* ConnectivityGrid::newStream(Http::ResponseDecoder& ConnectionPool::Cancellable* ret = wrapped_callback.get(); LinkedList::moveIntoList(std::move(wrapped_callback), wrapped_callbacks_); // Note that in the case of immediate attempt/failure, newStream will delete this. - if (wrapped_callbacks_.front()->newStream()) { + if (wrapped_callbacks_.front()->newStream() == StreamCreationResult::ImmediateResult) { // If newStream succeeds, return nullptr as the caller has received their // callback and does not need a cancellable handle. return nullptr; diff --git a/source/common/http/conn_pool_grid.h b/source/common/http/conn_pool_grid.h index db1dea5f28994..bd1989f81e6e6 100644 --- a/source/common/http/conn_pool_grid.h +++ b/source/common/http/conn_pool_grid.h @@ -19,6 +19,11 @@ class ConnectivityGrid : public ConnectionPool::Instance, std::vector protocols_; }; + enum class StreamCreationResult { + ImmediateResult, + StreamCreationPending, + }; + using PoolIterator = std::list::iterator; // This is a class which wraps a caller's connection pool callbacks to @@ -38,8 +43,7 @@ class ConnectivityGrid : public ConnectionPool::Instance, public: ConnectionAttemptCallbacks(WrapperCallbacks& parent, PoolIterator it); - // Returns true if a stream is immediately created, false if it is pending. - bool newStream(); + StreamCreationResult newStream(); // ConnectionPool::Callbacks void onPoolFailure(ConnectionPool::PoolFailureReason reason, @@ -67,9 +71,8 @@ class ConnectivityGrid : public ConnectionPool::Instance, // ConnectionPool::Cancellable void cancel(Envoy::ConnectionPool::CancelPolicy cancel_policy) override; - // Attempt to create a new stream for pool(). Returns true if the stream has - // been created. - bool newStream(); + // Attempt to create a new stream for pool(). + StreamCreationResult newStream(); // Removes this from the owning list, deleting it. void deleteThis();