Skip to content

stall_detector: no backtrace if exception #2714

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,11 @@ void cpu_stall_detector::generate_trace() {
buf.append("Reactor stalled for ");
buf.append_decimal(uint64_t(delta / 1ms));
buf.append(" ms");
print_with_backtrace(buf, _config.oneline);
if (std::uncaught_exceptions() > 0) {
buf.append(", backtrace omitted (uncaught exception in progress)\n");
} else {
print_with_backtrace(buf, _config.oneline);
}
maybe_report_kernel_trace(buf);
}

Expand Down
52 changes: 52 additions & 0 deletions tests/unit/stall_detector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,58 @@ SEASTAR_THREAD_TEST_CASE(spin_in_kernel) {
test_spin_with_body("kernel", [] { mmap_populate(128 * 1024); });
}

// This test reproduces the issue described in https://github.com/scylladb/seastar/issues/2697
// The issue is reproduced most quickly using the following arguments:
// --blocked-reactor-notify-ms=1
// but it will happen with default arguments as well.
SEASTAR_THREAD_TEST_CASE(stall_detector_crash) {
// increase total_iters to increase chance of failure
// the value below is tuned to take about 1 second in
// release builds
constexpr auto total_iters = 100000;
constexpr int max_depth = 20;

auto now = [] { return std::chrono::high_resolution_clock::now(); };

auto recursive_thrower = [](auto self, int x) -> void {
if (x <= 0) {
throw std::runtime_error("foo");
} else {
try {
self(self, x - 1);
} catch (...) {
if (x & 0xF) {
throw;
}
}
}
};

auto next_yield = now();
for (int a = 1; a < total_iters; a++) {
if (now() > next_yield) {
// we need to periodically yield or else the stall reports will become
// less and less frequent as exponentially grow the report interval while
// the same task is running
thread::yield();
next_yield = now() + 40ms;
// the next line resets the suppression state which allows many more reports
// per second, increasing the chance of a failure
reactor::test::set_stall_detector_report_function({});
}

try {
recursive_thrower(recursive_thrower, a % max_depth);
} catch (...) {
}

if (a % 100000 == 0) {
fmt::print("Making progress: {:6.3f}%\n", 100. * a / total_iters);
}
}
}



#else

Expand Down