utils::is_timeout_exception: Ensure we handle nested exception types

Fixes #9922

storage proxy uses is_timeout_exception to traverse different code paths.
a6202ae079 broke this (because bit rot and
intermixing), by wrapping exception for information purposes.

This adds check of nested types in exception handling, as well as a test
for the routine itself.
This commit is contained in:
Calle Wilund
2022-01-17 08:43:41 +00:00
parent dc886d96d1
commit 97bb1be6f7
2 changed files with 24 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include "test/lib/cql_test_env.hh"
#include <seastar/core/manual_clock.hh>
#include <seastar/testing/test_case.hh>
#include <seastar/rpc/rpc_types.hh>
#include "utils/error_injection.hh"
#include "db/timeout_clock.hh"
#include "test/lib/cql_assertions.hh"
@@ -184,6 +185,27 @@ SEASTAR_TEST_CASE(test_error_exceptions) {
return make_ready_future<>();
}
SEASTAR_TEST_CASE(test_is_timeout_exception) {
for (auto ep : {
std::make_exception_ptr(seastar::rpc::timeout_error()),
std::make_exception_ptr(seastar::semaphore_timed_out()),
std::make_exception_ptr(seastar::timed_out_error()),
})
{
BOOST_TEST(is_timeout_exception(ep));
try {
std::rethrow_exception(ep);
} catch (...) {
try {
std::throw_with_nested(std::runtime_error("Hello"));
} catch (...) {
BOOST_TEST(is_timeout_exception(std::current_exception()));
}
}
}
return make_ready_future<>();
}
SEASTAR_TEST_CASE(test_inject_exception) {
utils::error_injection<true> errinj;

View File

@@ -80,6 +80,8 @@ bool is_timeout_exception(std::exception_ptr e) {
return true;
} catch (seastar::timed_out_error& unused) {
return true;
} catch (const std::nested_exception& e) {
return is_timeout_exception(e.nested_ptr());
} catch (...) {
}
return false;