diff --git a/.gitignore b/.gitignore index 7d7f1c591870..9082ac3dadeb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ user.bazelrc compile_commands.json test/envoye2e/tcp_metadata_exchange/testoutput test/envoye2e/http_metadata_exchange/testoutput -*.wasm \ No newline at end of file +*.wasm +.vscode diff --git a/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite.cc b/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite.cc index bbda3453f1a9..0031a73f6b11 100644 --- a/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite.cc +++ b/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite.cc @@ -63,12 +63,25 @@ Network::FilterStatus TcpClusterRewriteFilter::onNewConnection() { "tcp_cluster_rewrite: final tcp proxy cluster name {}", read_callbacks_->connection(), final_cluster_name); - // The data is mutable to allow other filters to change it. - read_callbacks_->connection().streamInfo().filterState()->setData( - TcpProxy::PerConnectionCluster::key(), - std::make_unique(final_cluster_name), - StreamInfo::FilterState::StateType::Mutable); + try { + // The data is mutable to allow other filters to change it. + read_callbacks_->connection().streamInfo().filterState()->setData( + TcpProxy::PerConnectionCluster::key(), + std::make_unique(final_cluster_name), + StreamInfo::FilterState::StateType::Mutable, + StreamInfo::FilterState::LifeSpan::DownstreamConnection); + } catch (const EnvoyException& e) { + ENVOY_CONN_LOG(critical, "tcp_cluster_rewrite: error setting data: {}", + read_callbacks_->connection(), e.what()); + throw; + } catch (...) { + ENVOY_LOG( + critical, + "tcp_cluster_rewrite: error setting data due to unknown exception"); + throw; + } } + return Network::FilterStatus::Continue; } diff --git a/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite_test.cc b/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite_test.cc index f19ac1275078..1a84af22bf7b 100644 --- a/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite_test.cc +++ b/src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite_test.cc @@ -63,7 +63,8 @@ TEST_F(TcpClusterRewriteFilterTest, ClusterRewrite) { TcpProxy::PerConnectionCluster::key(), std::make_unique( "hello.ns1.svc.cluster.local"), - StreamInfo::FilterState::StateType::Mutable); + StreamInfo::FilterState::StateType::Mutable, + StreamInfo::FilterState::LifeSpan::DownstreamConnection); filter_->onNewConnection(); EXPECT_TRUE( @@ -87,7 +88,8 @@ TEST_F(TcpClusterRewriteFilterTest, ClusterRewrite) { stream_info_.filterState()->setData( TcpProxy::PerConnectionCluster::key(), std::make_unique("hello.ns1.global"), - StreamInfo::FilterState::StateType::Mutable); + StreamInfo::FilterState::StateType::Mutable, + StreamInfo::FilterState::LifeSpan::DownstreamConnection); filter_->onNewConnection(); EXPECT_TRUE( @@ -111,7 +113,8 @@ TEST_F(TcpClusterRewriteFilterTest, ClusterRewrite) { stream_info_.filterState()->setData( TcpProxy::PerConnectionCluster::key(), std::make_unique("hello.ns1.global"), - StreamInfo::FilterState::StateType::Mutable); + StreamInfo::FilterState::StateType::Mutable, + StreamInfo::FilterState::LifeSpan::DownstreamConnection); filter_->onNewConnection(); EXPECT_TRUE(