Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions source/server/connection_handler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ void ConnectionHandlerImpl::ActiveTcpSocket::newConnection() {
socket_->setDetectedTransportProtocol(
Extensions::TransportSockets::TransportProtocolNames::get().RawBuffer);
}
// TODO(lambdai): add integration test
// TODO: Address issues in wider scope. See https://github.com/envoyproxy/envoy/issues/8925
// Erase accept filter states because accept filters may not get the opportunity to clean up.
// Particularly the assigned events need to reset before assigning new events in the follow up.
accept_filters_.clear();
// Create a new connection on this listener.
listener_.newConnection(std::move(socket_));
}
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/network/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ MockDrainDecision::MockDrainDecision() = default;
MockDrainDecision::~MockDrainDecision() = default;

MockListenerFilter::MockListenerFilter() = default;
MockListenerFilter::~MockListenerFilter() = default;
MockListenerFilter::~MockListenerFilter() { destroy_(); }

MockListenerFilterCallbacks::MockListenerFilterCallbacks() {
ON_CALL(*this, socket()).WillByDefault(ReturnRef(socket_));
Expand Down
1 change: 1 addition & 0 deletions test/mocks/network/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class MockListenerFilter : public ListenerFilter {
MockListenerFilter();
~MockListenerFilter() override;

MOCK_METHOD0(destroy_, void());
MOCK_METHOD1(onAccept, Network::FilterStatus(ListenerFilterCallbacks&));
};

Expand Down
20 changes: 14 additions & 6 deletions test/server/connection_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ TEST_F(ConnectionHandlerTest, NormalRedirect) {
EXPECT_CALL(test_listener2->socket_, localAddress()).WillRepeatedly(ReturnRef(alt_address));
handler_->addListener(*test_listener2);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
auto* test_filter = new NiceMock<Network::MockListenerFilter>();
EXPECT_CALL(*test_filter, destroy_());
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
bool redirected = false;
EXPECT_CALL(factory_, createListenerFilterChain(_))
Expand Down Expand Up @@ -432,6 +433,7 @@ TEST_F(ConnectionHandlerTest, FallbackToWildcardListener) {
handler_->addListener(*test_listener2);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
EXPECT_CALL(*test_filter, destroy_());
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
bool redirected = false;
EXPECT_CALL(factory_, createListenerFilterChain(_))
Expand Down Expand Up @@ -498,6 +500,7 @@ TEST_F(ConnectionHandlerTest, WildcardListenerWithOriginalDst) {
cb.socket().restoreLocalAddress(original_dst_address);
return Network::FilterStatus::Continue;
}));
EXPECT_CALL(*test_filter, destroy_());
EXPECT_CALL(*accepted_socket, restoreLocalAddress(original_dst_address));
EXPECT_CALL(*accepted_socket, localAddressRestored()).WillOnce(Return(true));
EXPECT_CALL(*accepted_socket, localAddress()).WillRepeatedly(ReturnRef(original_dst_address));
Expand Down Expand Up @@ -529,6 +532,7 @@ TEST_F(ConnectionHandlerTest, WildcardListenerWithNoOriginalDst) {
handler_->addListener(*test_listener1);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
EXPECT_CALL(*test_filter, destroy_());
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
Expand Down Expand Up @@ -586,6 +590,7 @@ TEST_F(ConnectionHandlerTest, TransportProtocolCustom) {
handler_->addListener(*test_listener);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
EXPECT_CALL(*test_filter, destroy_());
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
manager.addAcceptFilter(Network::ListenerFilterPtr{test_filter});
Expand Down Expand Up @@ -644,6 +649,7 @@ TEST_F(ConnectionHandlerTest, ListenerFilterTimeout) {

EXPECT_CALL(*timeout, disableTimer());
timeout->invokeCallback();
EXPECT_CALL(*test_filter, destroy_());
dispatcher_.clearDeferredDeleteList();
EXPECT_EQ(0UL, downstream_pre_cx_active.value());
EXPECT_EQ(1UL, stats_store_.counter("downstream_pre_cx_timeout").value());
Expand Down Expand Up @@ -672,7 +678,7 @@ TEST_F(ConnectionHandlerTest, ContinueOnListenerFilterTimeout) {
EXPECT_CALL(test_listener->socket_, localAddress());
handler_->addListener(*test_listener);

Network::MockListenerFilter* test_filter = new Network::MockListenerFilter();
Network::MockListenerFilter* test_filter = new NiceMock<Network::MockListenerFilter>();
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
manager.addAcceptFilter(Network::ListenerFilterPtr{test_filter});
Expand All @@ -691,7 +697,8 @@ TEST_F(ConnectionHandlerTest, ContinueOnListenerFilterTimeout) {
Stats::Gauge& downstream_pre_cx_active =
stats_store_.gauge("downstream_pre_cx_active", Stats::Gauge::ImportMode::Accumulate);
EXPECT_EQ(1UL, downstream_pre_cx_active.value());

EXPECT_CALL(*test_filter, destroy_());
// Barrier: test_filter must be destructed before findFilterChain
EXPECT_CALL(manager_, findFilterChain(_)).WillOnce(Return(nullptr));
EXPECT_CALL(*timeout, disableTimer());
timeout->invokeCallback();
Expand All @@ -708,7 +715,6 @@ TEST_F(ConnectionHandlerTest, ContinueOnListenerFilterTimeout) {
// Timeout is disabled once the listener filters complete.
TEST_F(ConnectionHandlerTest, ListenerFilterTimeoutResetOnSuccess) {
InSequence s;

TestListener* test_listener = addListener(1, true, false, "test_listener");
Network::MockListener* listener = new Network::MockListener();
Network::ListenerCallbacks* listener_callbacks;
Expand Down Expand Up @@ -740,7 +746,7 @@ TEST_F(ConnectionHandlerTest, ListenerFilterTimeoutResetOnSuccess) {
Event::MockTimer* timeout = new Event::MockTimer(&dispatcher_);
EXPECT_CALL(*timeout, enableTimer(std::chrono::milliseconds(15000), _));
listener_callbacks->onAccept(Network::ConnectionSocketPtr{accepted_socket});

EXPECT_CALL(*test_filter, destroy_());
EXPECT_CALL(manager_, findFilterChain(_)).WillOnce(Return(nullptr));
EXPECT_CALL(*timeout, disableTimer());
listener_filter_cb->continueFilterChain(true);
Expand Down Expand Up @@ -777,6 +783,7 @@ TEST_F(ConnectionHandlerTest, ListenerFilterDisabledTimeout) {
return Network::FilterStatus::StopIteration;
}));
EXPECT_CALL(dispatcher_, createTimer_(_)).Times(0);
EXPECT_CALL(*test_filter, destroy_());
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
listener_callbacks->onAccept(Network::ConnectionSocketPtr{accepted_socket});

Expand All @@ -801,7 +808,6 @@ TEST_F(ConnectionHandlerTest, ListenerFilterReportError) {

Network::MockListenerFilter* first_filter = new Network::MockListenerFilter();
Network::MockListenerFilter* last_filter = new Network::MockListenerFilter();

EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillRepeatedly(Invoke([&](Network::ListenerFilterManager& manager) -> bool {
manager.addAcceptFilter(Network::ListenerFilterPtr{first_filter});
Expand All @@ -816,6 +822,8 @@ TEST_F(ConnectionHandlerTest, ListenerFilterReportError) {
}));
// The last filter won't be invoked
EXPECT_CALL(*last_filter, onAccept(_)).Times(0);
EXPECT_CALL(*first_filter, destroy_());
EXPECT_CALL(*last_filter, destroy_());
Network::MockConnectionSocket* accepted_socket = new NiceMock<Network::MockConnectionSocket>();
listener_callbacks->onAccept(Network::ConnectionSocketPtr{accepted_socket});

Expand Down