From 4a00a145259489a0aabad181377d468f0d5ac3e6 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Thu, 9 Sep 2021 06:11:59 +0000 Subject: [PATCH] crimson/net: bind() respects now ms_bind_retry_{delay,count}. Signed-off-by: Radoslaw Zarzynski --- src/crimson/net/Messenger.h | 4 --- src/crimson/net/SocketMessenger.cc | 55 +++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/crimson/net/Messenger.h b/src/crimson/net/Messenger.h index 10d9feae3df..5be2d689c3a 100644 --- a/src/crimson/net/Messenger.h +++ b/src/crimson/net/Messenger.h @@ -69,10 +69,6 @@ public: /// bind to the given address virtual bind_ertr::future<> bind(const entity_addrvec_t& addr) = 0; - /// try to bind to the first unused port of given address - virtual bind_ertr::future<> try_bind(const entity_addrvec_t& addr, - uint32_t min_port, uint32_t max_port) = 0; - /// start the messenger virtual seastar::future<> start(const dispatchers_t&) = 0; diff --git a/src/crimson/net/SocketMessenger.cc b/src/crimson/net/SocketMessenger.cc index 2922c3a6d23..c688bd139fc 100644 --- a/src/crimson/net/SocketMessenger.cc +++ b/src/crimson/net/SocketMessenger.cc @@ -77,14 +77,6 @@ SocketMessenger::do_listen(const entity_addrvec_t& addrs) }); } -SocketMessenger::bind_ertr::future<> -SocketMessenger::bind(const entity_addrvec_t& addrs) -{ - return do_bind(addrs).safe_then([this] { - logger().info("{} bind: done", *this); - }); -} - SocketMessenger::bind_ertr::future<> SocketMessenger::try_bind(const entity_addrvec_t& addrs, uint32_t min_port, uint32_t max_port) @@ -126,6 +118,53 @@ SocketMessenger::try_bind(const entity_addrvec_t& addrs, } else if (e == std::errc::address_not_available) { return crimson::ct_error::address_not_available::make(); } + ceph_abort(); + }); + }); +} + +SocketMessenger::bind_ertr::future<> +SocketMessenger::bind(const entity_addrvec_t& addrs) +{ + using crimson::common::local_conf; + return seastar::do_with(int64_t{local_conf()->ms_bind_retry_count}, + [this, &addrs] (auto& count) { + return seastar::repeat_until_value([this, &addrs, &count] { + assert(count >= 0); + return try_bind(addrs, + local_conf()->ms_bind_port_min, + local_conf()->ms_bind_port_max) + .safe_then([this] { + logger().info("{} try_bind: done", *this); + return seastar::make_ready_future>( + std::make_optional(std::error_code{/* success! */})); + }, bind_ertr::all_same_way([this, &count] (const std::error_code error) { + if (count-- > 0) { + logger().info("{} was unable to bind. Trying again in {} seconds", + *this, local_conf()->ms_bind_retry_delay); + return seastar::sleep( + std::chrono::seconds(local_conf()->ms_bind_retry_delay) + ).then([] { + // one more time, please + return seastar::make_ready_future>( + std::optional{std::nullopt}); + }); + } else { + logger().info("{} was unable to bind after {} attempts: {}", + *this, local_conf()->ms_bind_retry_count, error); + return seastar::make_ready_future>( + std::make_optional(error)); + } + })); + }).then([] (const std::error_code error) -> bind_ertr::future<> { + if (!error) { + return bind_ertr::now(); // success! + } else if (error == std::errc::address_in_use) { + return crimson::ct_error::address_in_use::make(); + } else if (error == std::errc::address_not_available) { + return crimson::ct_error::address_not_available::make(); + } + ceph_abort(); }); }); } -- 2.39.5