From d369c743ab170236582dbf0efddd330a32a9534e Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Tue, 13 Oct 2020 10:58:15 -0400 Subject: [PATCH 1/4] Prevent SEGFAULT when disabling listener (#13515) This prevents the stop_listening overload action from causing segmentation faults that can occur if the action is enabled after the listener has already shut down. Signed-off-by: Alex Konradi Signed-off-by: Christoph Pakulski --- source/server/connection_handler_impl.cc | 12 ++++++++++++ source/server/connection_handler_impl.h | 4 ++-- test/server/connection_handler_test.cc | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/source/server/connection_handler_impl.cc b/source/server/connection_handler_impl.cc index 0ca74c60c428..fd5586fb78cd 100644 --- a/source/server/connection_handler_impl.cc +++ b/source/server/connection_handler_impl.cc @@ -423,6 +423,18 @@ void ConnectionHandlerImpl::ActiveTcpListener::onAcceptWorker( } } +void ConnectionHandlerImpl::ActiveTcpListener::pauseListening() { + if (listener_ != nullptr) { + listener_->disable(); + } +} + +void ConnectionHandlerImpl::ActiveTcpListener::resumeListening() { + if (listener_ != nullptr) { + listener_->enable(); + } +} + void ConnectionHandlerImpl::ActiveTcpListener::newConnection( Network::ConnectionSocketPtr&& socket, std::unique_ptr stream_info) { // Find matching filter chain. diff --git a/source/server/connection_handler_impl.h b/source/server/connection_handler_impl.h index 3eb3e8e58c35..62ddf0c11be7 100644 --- a/source/server/connection_handler_impl.h +++ b/source/server/connection_handler_impl.h @@ -137,8 +137,8 @@ class ConnectionHandlerImpl : public Network::ConnectionHandler, // ActiveListenerImplBase Network::Listener* listener() override { return listener_.get(); } - void pauseListening() override { listener_->disable(); } - void resumeListening() override { listener_->enable(); } + void pauseListening() override; + void resumeListening() override; void shutdownListener() override { listener_.reset(); } // Network::BalancedConnectionHandler diff --git a/test/server/connection_handler_test.cc b/test/server/connection_handler_test.cc index 47d58f94e256..dbb6a5698e43 100644 --- a/test/server/connection_handler_test.cc +++ b/test/server/connection_handler_test.cc @@ -451,6 +451,22 @@ TEST_F(ConnectionHandlerTest, AddDisabledListener) { handler_->addListener(absl::nullopt, *test_listener); } +TEST_F(ConnectionHandlerTest, DisableListenerAfterStop) { + InSequence s; + + Network::TcpListenerCallbacks* listener_callbacks; + auto listener = new NiceMock(); + TestListener* test_listener = + addListener(1, false, false, "test_listener", listener, &listener_callbacks); + EXPECT_CALL(*socket_factory_, localAddress()).WillOnce(ReturnRef(local_address_)); + handler_->addListener(absl::nullopt, *test_listener); + + EXPECT_CALL(*listener, onDestroy()); + + handler_->stopListeners(); + handler_->disableListeners(); +} + TEST_F(ConnectionHandlerTest, DestroyCloseConnections) { InSequence s; From e593f0439d9029e1fc6aaf29ab690526d9018057 Mon Sep 17 00:00:00 2001 From: Christoph Pakulski Date: Tue, 3 Nov 2020 18:26:05 +0000 Subject: [PATCH 2/4] Fixed docs TOC to include 1.16.0 Signed-off-by: Christoph Pakulski --- docs/root/version_history/version_history.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/root/version_history/version_history.rst b/docs/root/version_history/version_history.rst index 4e37d1cb1b49..453bda753f1f 100644 --- a/docs/root/version_history/version_history.rst +++ b/docs/root/version_history/version_history.rst @@ -7,6 +7,7 @@ Version history :titlesonly: current + v1.16.0 v1.15.2 v1.15.1 v1.15.0 From 4798c00e8b7279e4f5039976a531f5b76dc05615 Mon Sep 17 00:00:00 2001 From: Christoph Pakulski Date: Tue, 3 Nov 2020 22:56:52 +0000 Subject: [PATCH 3/4] Added release notes. Signed-off-by: Christoph Pakulski --- docs/root/version_history/current.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index 9a4d1b7e40a8..f0b3e4fd3c8a 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -12,6 +12,11 @@ Minor Behavior Changes Bug Fixes --------- *Changes expected to improve the state of the world and are unlikely to have negative effects* +* overload: prevent segfault when disabling listener. + + This prevents the stop_listening overload action from causing + segmentation faults that can occur if the action is enabled after the + listener has already shut down. Removed Config or Runtime ------------------------- From 5363ac1c49635aedc01232b58c62123b600b6388 Mon Sep 17 00:00:00 2001 From: Christoph Pakulski Date: Thu, 5 Nov 2020 02:51:51 +0000 Subject: [PATCH 4/4] Corrected release note. Signed-off-by: Christoph Pakulski --- docs/root/version_history/current.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index f0b3e4fd3c8a..8300923b8150 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -12,11 +12,7 @@ Minor Behavior Changes Bug Fixes --------- *Changes expected to improve the state of the world and are unlikely to have negative effects* -* overload: prevent segfault when disabling listener. - - This prevents the stop_listening overload action from causing - segmentation faults that can occur if the action is enabled after the - listener has already shut down. +* listener: fix crash when disabling or re-enabling listeners due to overload while processing LDS updates. Removed Config or Runtime -------------------------