[COMMIT seastar master] rpc: introduce `server::abort_connection(connection_id)`

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
May 25, 2023, 6:29:35 AM5/25/23
to seastar-dev@googlegroups.com, Kamil Braun
From: Kamil Braun <kbr...@scylladb.com>
Committer: Kamil Braun <kbr...@scylladb.com>
Branch: master

rpc: introduce `server::abort_connection(connection_id)`

Can be used for aborting unwanted connections by the user (e.g. from
within a handler).

---
diff --git a/include/seastar/rpc/rpc.hh b/include/seastar/rpc/rpc.hh
--- a/include/seastar/rpc/rpc.hh
+++ b/include/seastar/rpc/rpc.hh
@@ -623,6 +623,14 @@ public:
f(*c.second);
}
}
+ /**
+ * Abort the given connection, causing it to stop receiving any further messages.
+ * It's safe to abort a connection from an RPC handler running on that connection.
+ * Does nothing if there is no connection with the given ID on this server.
+ *
+ * @param id the ID of the connection to abort.
+ */
+ void abort_connection(connection_id id);
gate& reply_gate() {
return _reply_gate;
}
diff --git a/src/rpc/rpc.cc b/src/rpc/rpc.cc
--- a/src/rpc/rpc.cc
+++ b/src/rpc/rpc.cc
@@ -1184,6 +1184,19 @@ future<> server::connection::send_unknown_verb_reply(std::optional<rpc_clock_typ
).discard_result();
}

+ void server::abort_connection(connection_id id) {
+ auto it = _conns.find(id);
+ if (it == _conns.end()) {
+ return;
+ }
+ try {
+ it->second->abort();
+ } catch (...) {
+ log_exception(*it->second, log_level::error,
+ "fail to shutdown connection on user request", std::current_exception());
+ }
+ }
+
std::ostream& operator<<(std::ostream& os, const connection_id& id) {
fmt::print(os, "{:x}", id.id);
return os;
Reply all
Reply to author
Forward
0 new messages