From 634027f3c6c74cf2d0783cab2cc7998215032e43 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 9 Jan 2023 09:30:48 +0000 Subject: [PATCH] cloud_storage: shutdown http client on partition stop This enables cluster::partition::stop to proceed promptly, rather than being blocked if ntp_archiver has an S3 request in flight. Fixes: https://github.com/redpanda-data/redpanda/issues/8071 --- src/v/cloud_storage/remote.cc | 15 +++++++++++++++ src/v/cloud_storage/remote.h | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/v/cloud_storage/remote.cc b/src/v/cloud_storage/remote.cc index 8ffbfb92fec7c..e7f0ab4cc1769 100644 --- a/src/v/cloud_storage/remote.cc +++ b/src/v/cloud_storage/remote.cc @@ -325,6 +325,21 @@ ss::future remote::upload_segment( co_return upload_result::cancelled; } + // If the uploading partition wishes to stop while an upload is in + // progress, enable this by forcefully shutting down the HTTP client. + auto as_sub = fib.root_abort_source().subscribe( + // Lifetimes: + // - `lease` is scoped to this function, as is the + // abort source subscription: as will always be deregistered + // before lease is destroyed. + // - `ctxlog` is also function scoped. + [&lease, &ctxlog]() noexcept { + vlog( + ctxlog.debug, + "Cancelling in-flight requests on partition shutdown"); + lease.client->shutdown(); + }); + auto reader_handle = co_await reset_str(); auto path = cloud_storage_clients::object_key(segment_path()); // Segment upload attempt diff --git a/src/v/cloud_storage/remote.h b/src/v/cloud_storage/remote.h index 39249da076621..abe3277aaa68b 100644 --- a/src/v/cloud_storage/remote.h +++ b/src/v/cloud_storage/remote.h @@ -46,7 +46,6 @@ struct lazy_abort_source { : _predicate{std::move(predicate)} {} bool abort_requested(); - ss::sstring abort_reason() const; private: