Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up remaining streams in TcpConnPool dtor #34065

Merged
merged 4 commits into from
May 15, 2024
Merged
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/extensions/upstreams/http/tcp/upstream_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ class TcpConnPool : public Router::GenericConnPool, public Envoy::Tcp::Connectio
Upstream::ResourcePriority priority, Upstream::LoadBalancerContext* ctx) {
conn_pool_data_ = thread_local_cluster.tcpConnPool(priority, ctx);
}
~TcpConnPool() override {
ENVOY_BUG(upstream_handle_ == nullptr, "upstream_handle not null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't a no-op to call the ENVOY_BUG after the cancel? I think it needs to be called before to be useful
/wait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh also just noticed cancelAnyPendingStream is virtual.
Can you move the code to a non-virtual cancelAnyPendingStreamImpl and call that here, to avoid any issues with virtual code from destructor?
Hopefully the last pass!

resetUpstreamHandleIfSet();
}
// Router::GenericConnPool
void newStream(Router::GenericConnectionPoolCallbacks* callbacks) override {
callbacks_ = callbacks;
upstream_handle_ = conn_pool_data_.value().newConnection(*this);
}
bool cancelAnyPendingStream() override {
if (upstream_handle_) {
upstream_handle_->cancel(Envoy::Tcp::ConnectionPool::CancelPolicy::Default);
upstream_handle_ = nullptr;
return true;
}
return false;
}
bool cancelAnyPendingStream() override { return resetUpstreamHandleIfSet(); }
Upstream::HostDescriptionConstSharedPtr host() const override {
return conn_pool_data_.value().host();
}
Expand All @@ -56,6 +53,15 @@ class TcpConnPool : public Router::GenericConnPool, public Envoy::Tcp::Connectio
Upstream::HostDescriptionConstSharedPtr host) override;

private:
bool resetUpstreamHandleIfSet() {
if (upstream_handle_) {
upstream_handle_->cancel(Envoy::Tcp::ConnectionPool::CancelPolicy::Default);
upstream_handle_ = nullptr;
return true;
}
return false;
}

absl::optional<Envoy::Upstream::TcpPoolData> conn_pool_data_;
Envoy::Tcp::ConnectionPool::Cancellable* upstream_handle_{};
Router::GenericConnectionPoolCallbacks* callbacks_{};
Expand Down
Loading