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

shard_connection: Handle non-blocking I/O errors on Unix socket client connect #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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: 16 additions & 5 deletions shard_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,27 @@ int shard_connection::connect(struct connect_info* addr) {
// call connect
m_connection_state = conn_in_progress;

if (bufferevent_socket_connect(m_bev,
m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr,
m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == -1) {
while (true) {
if (bufferevent_socket_connect(m_bev,
m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr,
m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == 0) {
return 0;
}

if (errno == EINPROGRESS) {
return 0;
}

if (errno == EAGAIN || errno == EWOULDBLOCK) {
// resource temporarily unavailable; try again
continue;
}

disconnect();

benchmark_error_log("connect failed, error = %s\n", strerror(errno));
return -1;
}

return 0;
}

void shard_connection::disconnect() {
Expand Down