Skip to content

Commit

Permalink
Create a new TcpSocket when connection failed (#3840)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi authored Jan 26, 2021
1 parent 0235050 commit 5005b7b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/network/linkers_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,21 @@ void Linkers::Construct() {
int out_rank = it->first;
// let smaller rank connect to larger rank
if (out_rank > rank_) {
TcpSocket cur_socket;
int connect_fail_delay_time = connect_fail_retry_first_delay_interval;
for (int i = 0; i < connect_fail_retry_cnt; ++i) {
TcpSocket cur_socket;
if (cur_socket.Connect(client_ips_[out_rank].c_str(), client_ports_[out_rank])) {
// send local rank
cur_socket.Send(reinterpret_cast<const char*>(&rank_), sizeof(rank_));
SetLinker(out_rank, cur_socket);
break;
} else {
Log::Warning("Connecting to rank %d failed, waiting for %d milliseconds", out_rank, connect_fail_delay_time);
cur_socket.Close();
std::this_thread::sleep_for(std::chrono::milliseconds(connect_fail_delay_time));
connect_fail_delay_time = static_cast<int>(connect_fail_delay_time * connect_fail_retry_delay_factor);
}
}
// send local rank
cur_socket.Send(reinterpret_cast<const char*>(&rank_), sizeof(rank_));
SetLinker(out_rank, cur_socket);
}
}
// wait for listener
Expand Down

0 comments on commit 5005b7b

Please sign in to comment.