Skip to content
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
15 changes: 14 additions & 1 deletion src/v/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <seastar/core/temporary_buffer.hh>
#include <seastar/core/timed_out_error.hh>
#include <seastar/core/timer.hh>
#include <seastar/net/api.hh>
#include <seastar/net/tls.hh>

#include <boost/beast/core/buffer_traits.hpp>
Expand All @@ -42,6 +43,10 @@

namespace http {

constexpr std::chrono::seconds tcp_keepalive_idle = 360s;
constexpr std::chrono::seconds tcp_keepalive_interval = 120s;
constexpr unsigned int tcp_keepalive_probes = 10;

std::string_view content_type_string(content_type type) {
switch (type) {
case content_type::json:
Expand Down Expand Up @@ -133,7 +138,7 @@ ss::future<client::request_response_t> client::make_request(
}
}
return get_connected(timeout, ctxlog)
.then([req, res, target, ctxlog](reconnect_result_t r) {
.then([this, req, res, target, ctxlog](reconnect_result_t r) {
if (r == reconnect_result_t::timed_out) {
vlog(
ctxlog.warn,
Expand All @@ -142,6 +147,14 @@ ss::future<client::request_response_t> client::make_request(
ss::timed_out_error err;
return ss::make_exception_future<client::request_response_t>(err);
}
// Set keepalive after connection is established and we have a
// connected socket.
set_keepalive_parameters(ss::net::tcp_keepalive_params{
.idle = tcp_keepalive_idle,
.interval = tcp_keepalive_interval,
.count = tcp_keepalive_probes,
});
set_keepalive(true);
return ss::make_ready_future<request_response_t>(
std::make_tuple(req, res));
})
Expand Down
3 changes: 3 additions & 0 deletions src/v/net/include/net/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class base_transport {
void shutdown() noexcept;
ss::future<> wait_input_shutdown();

void set_keepalive_parameters(const ss::net::keepalive_params& params);
void set_keepalive(bool);

[[gnu::always_inline]] bool is_valid() const {
return _fd && !_shutdown && !_in.eof();
}
Expand Down
13 changes: 13 additions & 0 deletions src/v/net/transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ ss::future<> base_transport::do_connect(clock_type::time_point timeout) {
co_return;
}

void base_transport::set_keepalive_parameters(
const ss::net::keepalive_params& params) {
if (_fd) {
_fd->set_keepalive_parameters(params);
}
}

void base_transport::set_keepalive(bool keepalive) {
if (_fd) {
_fd->set_keepalive(keepalive);
}
}

ss::future<>
base_transport::connect(clock_type::time_point connection_timeout) {
// in order to hold concurrency correctness invariants we must guarantee 3
Expand Down