From 3c35d784b38897b102e5080ed36ff8d62d691f90 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 23 May 2022 12:04:54 +0100 Subject: [PATCH] cluster: swallog+log unexpected exceptions in report_metrics This can happen during shutdown, for the exception types that ssx::spawn_with_gate doesn't already handle. Rather rare in real life but much more frequent in tests like test_cluster_rpunit, resulting in an "ignored exceptional future" error. Fixes https://github.com/redpanda-data/redpanda/issues/4807 --- src/v/cluster/metrics_reporter.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/v/cluster/metrics_reporter.cc b/src/v/cluster/metrics_reporter.cc index d94b3e6f3a8e..f601639ba1c9 100644 --- a/src/v/cluster/metrics_reporter.cc +++ b/src/v/cluster/metrics_reporter.cc @@ -132,13 +132,16 @@ ss::future<> metrics_reporter::stop() { } void metrics_reporter::report_metrics() { - ssx::spawn_with_gate(_gate, [this] { - return do_report_metrics().finally([this] { - if (!_gate.is_closed()) { - _tick_timer.arm( - config::shard_local_cfg().metrics_reporter_tick_interval()); - } - }); + ssx::background = ssx::spawn_with_gate_then(_gate, [this] { + return do_report_metrics().finally([this] { + if (!_gate.is_closed()) { + _tick_timer.arm( + config::shard_local_cfg() + .metrics_reporter_tick_interval()); + } + }); + }).handle_exception([](const std::exception_ptr& e) { + vlog(clusterlog.warn, "Exception reporting metrics: {}", e); }); }