Skip to content

Commit

Permalink
rpc: optimize send error handling
Browse files Browse the repository at this point in the history
Remove the double dose of ssx::handle_shutdown_exceptions by inlining
the gate handling into a single place.

Remove the extra overhead of some lambdas and a couple of extra
continuations by handling unexpected errors and closing the gate in a
single continuation.

Signed-off-by: Tyler Rockwood <[email protected]>
  • Loading branch information
rockwotj committed Aug 10, 2023
1 parent 9670361 commit 0b3fa8c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/v/rpc/transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,24 @@ ss::future<> transport::do_dispatch_send() {
}

void transport::dispatch_send() {
ssx::spawn_with_gate(_dispatch_gate, [this]() mutable {
return ssx::ignore_shutdown_exceptions(do_dispatch_send())
.handle_exception([this](std::exception_ptr e) {
vlog(rpclog.info, "Error dispatching socket write:{}", e);
_probe->request_error();
fail_outstanding_futures();
});
});
// Callers expect this function does not throw, so check if the gate is
// closed so we know that `hold()` will never throw.
if (_dispatch_gate.is_closed()) {
return;
}
auto holder = _dispatch_gate.hold();
ssx::background = ssx::ignore_shutdown_exceptions(do_dispatch_send())
.then_wrapped(
[this, h = std::move(holder)](ss::future<> fut) {
if (fut.failed()) {
vlog(
rpclog.info,
"Error dispatching socket write:{}",
fut.get_exception());
_probe->request_error();
fail_outstanding_futures();
}
});
}

ss::future<> transport::do_reads() {
Expand Down

0 comments on commit 0b3fa8c

Please sign in to comment.