From 96ac0b2b7ebcc829f79e71d8d1a22105236a0af1 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Thu, 22 Jun 2023 21:03:16 +0100 Subject: [PATCH] net: ss::nested_exception might be a disconnect_exception Look through an ss::nested_exception to see if it's a `disconnect_exception`. Fixes #11617 Signed-off-by: Ben Pope (cherry picked from commit 2e10dcb6cd3c5f6eab865bc01b13b985199330fa) --- src/v/net/connection.cc | 7 +++++ src/v/net/tests/CMakeLists.txt | 10 +++++++ src/v/net/tests/connection.cc | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/v/net/tests/connection.cc diff --git a/src/v/net/connection.cc b/src/v/net/connection.cc index 792ddd2d5347..96dafc00dd8f 100644 --- a/src/v/net/connection.cc +++ b/src/v/net/connection.cc @@ -12,6 +12,8 @@ #include "net/exceptions.h" #include "rpc/service.h" +#include + #include namespace net { @@ -86,6 +88,11 @@ std::optional is_disconnect_exception(std::exception_ptr e) { return fmt::format("invalid request: {}", e.what()); } return "invalid request"; + } catch (const ss::nested_exception& e) { + if (auto err = is_disconnect_exception(e.inner)) { + return err; + } + return is_disconnect_exception(e.outer); } catch (...) { // Global catch-all prevents stranded/non-handled exceptional futures. // In all other non-explicity handled cases, the exception will not be diff --git a/src/v/net/tests/CMakeLists.txt b/src/v/net/tests/CMakeLists.txt index 0fa1e96027f6..6842c65fdf84 100644 --- a/src/v/net/tests/CMakeLists.txt +++ b/src/v/net/tests/CMakeLists.txt @@ -29,3 +29,13 @@ rp_test( ARGS "-- -c 1" LABELS net ) + +rp_test( + UNIT_TEST + BINARY_NAME net_connection + SOURCES + connection.cc + DEFINITIONS BOOST_TEST_DYN_LINK + LIBRARIES v::seastar_testing_main Boost::unit_test_framework v::net + LABELS net +) diff --git a/src/v/net/tests/connection.cc b/src/v/net/tests/connection.cc new file mode 100644 index 000000000000..345b2e626182 --- /dev/null +++ b/src/v/net/tests/connection.cc @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Redpanda Data, Inc. + * + * Licensed as a Redpanda Enterprise file under the Redpanda Community + * License (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://github.com/redpanda-data/redpanda/blob/master/licenses/rcl.md + */ + +#include "net/connection.h" + +#include + +#include +#include + +#include +#include + +BOOST_AUTO_TEST_CASE(test_is_disconnect_error) { + auto is_a_de = std::system_error( + std::make_error_code(std::errc::broken_pipe)); + auto not_a_de = std::system_error( + std::make_error_code(std::errc::is_a_directory)); + + BOOST_CHECK(net::is_disconnect_exception(std::make_exception_ptr(is_a_de)) + .has_value()); + + BOOST_CHECK(!net::is_disconnect_exception(std::make_exception_ptr(not_a_de)) + .has_value()); + + BOOST_CHECK( + net::is_disconnect_exception( + std::make_exception_ptr(ss::nested_exception( + std::make_exception_ptr(is_a_de), std::make_exception_ptr(not_a_de)))) + .has_value()); + + BOOST_CHECK( + net::is_disconnect_exception( + std::make_exception_ptr(ss::nested_exception( + std::make_exception_ptr(not_a_de), std::make_exception_ptr(is_a_de)))) + .has_value()); + + BOOST_CHECK(!net::is_disconnect_exception( + std::make_exception_ptr(ss::nested_exception( + std::make_exception_ptr(not_a_de), + std::make_exception_ptr(not_a_de)))) + .has_value()); +}