Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: ss::nested_exception might be a disconnect_exception #11619

Merged
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
7 changes: 7 additions & 0 deletions src/v/net/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "net/exceptions.h"
#include "rpc/service.h"

#include <seastar/core/future.hh>

#include <gnutls/gnutls.h>

namespace net {
Expand Down Expand Up @@ -87,6 +89,11 @@ std::optional<ss::sstring> 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
Expand Down
10 changes: 10 additions & 0 deletions src/v/net/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
50 changes: 50 additions & 0 deletions src/v/net/tests/connection.cc
Original file line number Diff line number Diff line change
@@ -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 <seastar/core/future.hh>

#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>

#include <exception>
#include <system_error>

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());
}