Skip to content

Commit

Permalink
Handle non-blocking I/O errors on Unix socket client connect
Browse files Browse the repository at this point in the history
  • Loading branch information
LINKIWI committed Jan 22, 2025
1 parent ae4c12b commit 7ff52af
Showing 1 changed file with 16 additions and 5 deletions.
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

0 comments on commit 7ff52af

Please sign in to comment.