]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/net: bind() respects now ms_bind_retry_{delay,count}.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 9 Sep 2021 06:11:59 +0000 (06:11 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 14 Sep 2021 10:01:35 +0000 (10:01 +0000)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/net/Messenger.h
src/crimson/net/SocketMessenger.cc

index 10d9feae3dff81c2a48fbc07e68a35e2a893835c..5be2d689c3a1dee411e27004bc910fef220f16f5 100644 (file)
@@ -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;
 
index 2922c3a6d2391930b397894c5724a3415e648d1a..c688bd139fc3bb3a79594690e9f354bf10645830 100644 (file)
@@ -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::optional<std::error_code>>(
+          std::make_optional<std::error_code>(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::error_code>>(
+              std::optional<std::error_code>{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::optional<std::error_code>>(
+            std::make_optional<std::error_code>(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();
     });
   });
 }