[QUEUED scylladb next-5.4] Merge '[Backport 5.4] Close output stream in task manager's API get_tasks handler' from Pavel Emelyanov

1 view
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Jul 1, 2024, 11:03:33 AMJul 1
to scylladb-dev@googlegroups.com, Pavel Emelyanov
From: Pavel Emelyanov <xe...@scylladb.com>
Committer: Pavel Emelyanov <xe...@scylladb.com>
Branch: next-5.4

Merge '[Backport 5.4] Close output stream in task manager's API get_tasks handler' from Pavel Emelyanov

If client stops reading response early, the server-side stream throws but must be closed anyway. Seen in another endpoint and fixed by https://github.com/scylladb/scylladb/pull/19541

Original commit is 0ce00ebfbd845d9f3f71ade3c5e726815635e265
Had simple conflict with ffb5ad494fcb5779a22ace8af694a91c8598b5a5

closes: #19560

Closes scylladb/scylladb#19571

* https://github.com/scylladb/scylladb:
api: Fix indentation after previous patch
api: Close response stream on error
api: Flush response output stream before closing

---
diff --git a/api/task_manager.cc b/api/task_manager.cc
--- a/api/task_manager.cc
+++ b/api/task_manager.cc
@@ -7,6 +7,7 @@
*/

#include <seastar/core/coroutine.hh>
+#include <seastar/coroutine/exception.hh>

#include "task_manager.hh"
#include "api/api-doc/task_manager.json.hh"
@@ -139,19 +140,28 @@ void set_task_manager(http_context& ctx, routes& r, db::config& cfg) {

std::function<future<>(output_stream<char>&&)> f = [r = std::move(res)] (output_stream<char>&& os) -> future<> {
auto s = std::move(os);
- auto res = std::move(r);
- co_await s.write("[");
- std::string delim = "";
- for (auto& v: res) {
- for (auto& stats: v) {
- co_await s.write(std::exchange(delim, ", "));
- tm::task_stats ts;
- ts = stats;
- co_await formatter::write(s, ts);
+ std::exception_ptr ex;
+ try {
+ auto res = std::move(r);
+ co_await s.write("[");
+ std::string delim = "";
+ for (auto& v: res) {
+ for (auto& stats: v) {
+ co_await s.write(std::exchange(delim, ", "));
+ tm::task_stats ts;
+ ts = stats;
+ co_await formatter::write(s, ts);
+ }
}
+ co_await s.write("]");
+ co_await s.flush();
+ } catch (...) {
+ ex = std::current_exception();
}
- co_await s.write("]");
co_await s.close();
+ if (ex) {
+ co_await coroutine::return_exception_ptr(std::move(ex));
+ }
};
co_return std::move(f);
});
Reply all
Reply to author
Forward
0 new messages