Skip to content

Commit

Permalink
Allow skipping retry when failed to connect
Browse files Browse the repository at this point in the history
Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow committed Dec 28, 2023
1 parent a54010a commit 08c2bc0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/client/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ limitations under the License.

#include <iostream>

#include "common/util/env.h"

namespace vineyard {

static const int kNumConnectAttempts = 10;
Expand Down Expand Up @@ -108,12 +110,16 @@ Status connect_ipc_socket_retry(const std::string& pathname, int& socket_fd) {

auto status = connect_ipc_socket(pathname, socket_fd);

bool skip_retry = read_env("VINEYARD_IPC_SKIP_RETRY", "0") == "1";
while (!status.ok() && num_retries > 0) {
std::clog << "[info] Connection to IPC socket failed for pathname "
<< pathname << " with ret = " << status << ", retrying "
<< num_retries << " more times." << std::endl;
usleep(static_cast<int>(timeout * 1000));
status = connect_ipc_socket(pathname, socket_fd);
if (!status.ok() && skip_retry) {
break;
}
--num_retries;
}
if (!status.ok()) {
Expand All @@ -130,12 +136,16 @@ Status connect_rpc_socket_retry(const std::string& host, const uint32_t port,

auto status = connect_rpc_socket(host, port, socket_fd);

bool skip_retry = read_env("VINEYARD_RPC_SKIP_RETRY", "0") == "1";
while (!status.ok() && num_retries > 0) {
std::clog << "[info] Connection to RPC socket failed for endpoint " << host
<< ":" << port << " with ret = " << status << ", retrying "
<< num_retries << " more times." << std::endl;
usleep(static_cast<int>(timeout * 1000));
status = connect_rpc_socket(host, port, socket_fd);
if (!status.ok() && skip_retry) {
break;
}
--num_retries;
}
if (!status.ok()) {
Expand Down

0 comments on commit 08c2bc0

Please sign in to comment.