Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ FilterStatus Router::UpstreamRequest::start() {
return FilterStatus::StopIteration;
}

if (upstream_host_ == nullptr) {
return FilterStatus::StopIteration;
}

return FilterStatus::Continue;
}

Expand Down Expand Up @@ -502,9 +506,8 @@ void Router::UpstreamRequest::onResetStream(ConnectionPool::PoolFailureReason re
switch (reason) {
case ConnectionPool::PoolFailureReason::Overflow:
parent_.callbacks_->sendLocalReply(
AppException(
AppExceptionType::InternalError,
fmt::format("too many connections to '{}'", upstream_host_->address()->asString())),
AppException(AppExceptionType::InternalError,
"thrift upstream request: too many connections"),
true);
break;
case ConnectionPool::PoolFailureReason::LocalConnectionFailure:
Expand All @@ -519,7 +522,9 @@ void Router::UpstreamRequest::onResetStream(ConnectionPool::PoolFailureReason re
parent_.callbacks_->sendLocalReply(
AppException(
AppExceptionType::InternalError,
fmt::format("connection failure '{}'", upstream_host_->address()->asString())),
fmt::format("connection failure '{}'", (upstream_host_ != nullptr)
? upstream_host_->address()->asString()
: "to upstream")),
true);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion test/extensions/filters/network/thrift_proxy/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ TEST_F(ThriftRouterTest, PoolOverflowFailure) {
EXPECT_THAT(app_ex.what(), ContainsRegex(".*too many connections.*"));
EXPECT_TRUE(end_stream);
}));
context_.cluster_manager_.tcp_conn_pool_.poolFailure(ConnectionPool::PoolFailureReason::Overflow);
context_.cluster_manager_.tcp_conn_pool_.poolFailureWithNullHost(
ConnectionPool::PoolFailureReason::Overflow);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

verified that this crashes without your fix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes,if i use the previous code ,it will crash in my ci like this .

[ RUN      ] ThriftRouterTest.PoolOverflowFailure
TestRandomGenerator running with seed -443243904
[2020-09-09 13:03:11.969][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:104] Caught Segmentation fault, suspect faulting address 0x0
[2020-09-09 13:03:11.969][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:91] Backtrace (use tools/stack_decode.py to get line numbers):
[2020-09-09 13:03:11.969][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:92] Envoy version: 0/1.16.0-dev/test/RELEASE/BoringSSL
[2020-09-09 13:03:11.969][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #0: __restore_rt [0x7faf6ee3a8a0]
[2020-09-09 13:03:11.975][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #1: Envoy::Tcp::ConnectionPool::MockInstance::poolFailure() [0x9b3dd3]
[2020-09-09 13:03:11.981][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #2: Envoy::Extensions::NetworkFilters::ThriftProxy::Router::ThriftRouterTest_PoolOverflowFailure_Test::TestBody() [0x788b44]
[2020-09-09 13:03:11.987][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #3: testing::internal::HandleExceptionsInMethodIfSupported<>() [0x1293a78]
[2020-09-09 13:03:11.992][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #4: testing::Test::Run() [0x12939a5]
[2020-09-09 13:03:11.998][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #5: testing::TestInfo::Run() [0x12947f0]
[2020-09-09 13:03:12.003][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #6: testing::TestSuite::Run() [0x1295177]
[2020-09-09 13:03:12.009][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #7: testing::internal::UnitTestImpl::RunAllTests() [0x12a2047]
[2020-09-09 13:03:12.015][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #8: testing::internal::HandleExceptionsInMethodIfSupported<>() [0x12a1968]
[2020-09-09 13:03:12.020][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #9: testing::UnitTest::Run() [0x12a17ef]
[2020-09-09 13:03:12.026][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #10: Envoy::TestRunner::RunTests() [0xbf1734]
[2020-09-09 13:03:12.031][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #11: main [0xbf092b]
[2020-09-09 13:03:12.032][5454][critical][backtrace] [bazel-out/k8-opt/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:96] #12: __libc_start_main [0x7faf6ea58b97]
================================================================================
INFO: Elapsed time: 1017.162s, Critical Path: 329.15s

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thanks.

}

TEST_F(ThriftRouterTest, PoolConnectionFailureWithOnewayMessage) {
Expand Down
8 changes: 7 additions & 1 deletion test/mocks/tcp/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ void MockInstance::poolFailure(PoolFailureReason reason) {
Callbacks* cb = callbacks_.front();
callbacks_.pop_front();
handles_.pop_front();

cb->onPoolFailure(reason, host_);
}

void MockInstance::poolFailureWithNullHost(PoolFailureReason reason) {
Callbacks* cb = callbacks_.front();
callbacks_.pop_front();
handles_.pop_front();
cb->onPoolFailure(reason, nullptr);
}

void MockInstance::poolReady(Network::MockClientConnection& conn) {
Callbacks* cb = callbacks_.front();
callbacks_.pop_front();
Expand Down
1 change: 1 addition & 0 deletions test/mocks/tcp/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MockInstance : public Instance {

Envoy::ConnectionPool::MockCancellable* newConnectionImpl(Callbacks& cb);
void poolFailure(PoolFailureReason reason);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can probably just add a bool host_null param and reuse poolFailure()

void poolFailureWithNullHost(PoolFailureReason reason);
void poolReady(Network::MockClientConnection& conn);

// Invoked when connection_data_, having been assigned via poolReady is released.
Expand Down