Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to connect again if refused error found #747

Merged
merged 4 commits into from
Dec 23, 2016
Merged
Changes from 3 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
21 changes: 19 additions & 2 deletions paddle/pserver/LightNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License. */
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <chrono>

#include <arpa/inet.h>
#include <net/if.h>
Expand Down Expand Up @@ -49,6 +50,10 @@ DEFINE_int32(sock_recv_buf_size,
1024 * 1024 * 40,
"restrict sock recv buff size");

DEFINE_int32(connrefused_retries_second,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个改成常量吧。目前Paddle不允许在Main文件之外的文件新增gflags

10,
"retry connrefused_retries_second if ECONNREFUSED occurs");

namespace paddle {

/**
Expand Down Expand Up @@ -382,8 +387,20 @@ void SocketClient::TcpClient(const std::string &serverAddr, int serverPort) {
setOption(sockfd);

/// Now connect to the server
PCHECK(connect(sockfd, (sockaddr *)&serv_addr, sizeof(serv_addr)) >= 0)
<< "ERROR connecting to " << serverAddr;
int retry_second = 0;
int error = 0;
do {
error = connect(sockfd, (sockaddr *)&serv_addr, sizeof(serv_addr));
if (error == ECONNREFUSED) {
LOG(WARNING) << "connection refused by pserver, try again!";
if (retry_second++ >= FLAGS_connrefused_retries_second) {
LOG(FATAL) << "connection refused by pserver, maybe pserver failed!";
}
std::this_thread::sleep_for(std::chrono::seconds(1));
} else {
PCHECK(error >= 0) << "ERROR connecting to " << serverAddr;
}
} while (error == ECONNREFUSED);

channel_.reset(new SocketChannel(sockfd, serverAddr));
tcpRdma_ = F_TCP;
Expand Down