Skip to content

Commit

Permalink
Merge pull request redpanda-data#23540 from nvartolomei/nv/sleep-abor…
Browse files Browse the repository at this point in the history
…table-hang

ssx: exit early from sleep_abortable if already aborted
  • Loading branch information
nvartolomei authored Sep 29, 2024
2 parents fd7f298 + 9937975 commit 4955fb2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/v/ssx/sleep_abortable.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ sleep_abortable(typename Clock::duration dur, AbortSource&... src) {
}
seastar::weak_ptr<as_state> state;
};

if ((src.abort_requested() || ...)) {
return seastar::make_exception_future<>(seastar::sleep_aborted());
}

auto state = seastar::make_lw_shared<as_state>();
state->subscriptions.reserve(sizeof...(AbortSource));
as_callback cb(*state);
Expand Down
32 changes: 32 additions & 0 deletions src/v/ssx/tests/sleep_abortable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort1) {
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort1_pre) {
ss::abort_source as;

as.request_abort();
auto fut = ssx::sleep_abortable(1000s, as);
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_normal1) {
ss::abort_source as;
ssx::sleep_abortable(10ms, as).get();
Expand All @@ -51,6 +59,15 @@ SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort2) {
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort2_pre) {
ss::abort_source as1;
ss::abort_source as2;

as1.request_abort();
auto fut = ssx::sleep_abortable(1000s, as1, as2);
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort3) {
ss::abort_source as1, as2, as3;

Expand All @@ -60,6 +77,14 @@ SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort3) {
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort3_pre) {
ss::abort_source as1, as2, as3;

as3.request_abort();
auto fut = ssx::sleep_abortable(1000s, as1, as2, as3);
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort4) {
ss::abort_source as1, as2, as3, as4;
auto fut = ssx::sleep_abortable(1000s, as1, as2, as3, as4);
Expand All @@ -68,6 +93,13 @@ SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort4) {
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_abort4_pre) {
ss::abort_source as1, as2, as3, as4;
as2.request_abort();
auto fut = ssx::sleep_abortable(1000s, as1, as2, as3, as4);
BOOST_REQUIRE_THROW(fut.get(), ss::sleep_aborted);
}

SEASTAR_THREAD_TEST_CASE(sleep_abortable_aborted_twice) {
ss::abort_source as1, as2;
auto fut = ssx::sleep_abortable(1000s, as1, as2);
Expand Down

0 comments on commit 4955fb2

Please sign in to comment.