Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc/transport: release caller units when timeout occurs #6738

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/v/rpc/transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ transport::send(netbuf b, rpc::client_opts opts) {
}

ss::future<result<std::unique_ptr<streaming_context>>>
transport::make_response_handler(netbuf& b, const rpc::client_opts& opts) {
transport::make_response_handler(
netbuf& b, const rpc::client_opts& opts, sequence_t seq) {
if (_correlations.find(_correlation_idx + 1) != _correlations.end()) {
_probe.client_correlation_error();
vlog(
Expand All @@ -151,7 +152,14 @@ transport::make_response_handler(netbuf& b, const rpc::client_opts& opts) {
throw std::logic_error(
fmt::format("Tried to reuse correlation id: {}", idx));
}
item_raw_ptr->with_timeout(opts.timeout, [this, idx] {
item_raw_ptr->with_timeout(opts.timeout, [this, idx, seq] {
/*
* remove pending entry from requests queue. If a timeout occurred
* before an entry was sent we can not keep the entry alive as it may
* contain caller semaphore units, the units must be released when we
* notify caller with the result.
*/
_requests_queue.erase(seq);
auto it = _correlations.find(idx);
if (likely(it != _correlations.end())) {
vlog(
Expand Down Expand Up @@ -180,7 +188,7 @@ transport::do_send(sequence_t seq, netbuf b, rpc::client_opts opts) {
return ss::with_gate(
_dispatch_gate,
[this, b = std::move(b), opts = std::move(opts), seq]() mutable {
auto f = make_response_handler(b, opts);
auto f = make_response_handler(b, opts, seq);

// send
auto sz = b.buffer().size_bytes();
Expand Down
2 changes: 1 addition & 1 deletion src/v/rpc/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class transport final : public net::base_transport {
void dispatch_send();

ss::future<result<std::unique_ptr<streaming_context>>>
make_response_handler(netbuf&, const rpc::client_opts&);
make_response_handler(netbuf&, const rpc::client_opts&, sequence_t);

ssx::semaphore _memory;
/**
Expand Down