Skip to content

Commit 7ff52af

Browse files
committed
Handle non-blocking I/O errors on Unix socket client connect
1 parent ae4c12b commit 7ff52af

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

shard_connection.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,27 @@ int shard_connection::connect(struct connect_info* addr) {
288288
// call connect
289289
m_connection_state = conn_in_progress;
290290

291-
if (bufferevent_socket_connect(m_bev,
292-
m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr,
293-
m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == -1) {
291+
while (true) {
292+
if (bufferevent_socket_connect(m_bev,
293+
m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr,
294+
m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == 0) {
295+
return 0;
296+
}
297+
298+
if (errno == EINPROGRESS) {
299+
return 0;
300+
}
301+
302+
if (errno == EAGAIN || errno == EWOULDBLOCK) {
303+
// resource temporarily unavailable; try again
304+
continue;
305+
}
306+
294307
disconnect();
295308

296309
benchmark_error_log("connect failed, error = %s\n", strerror(errno));
297310
return -1;
298311
}
299-
300-
return 0;
301312
}
302313

303314
void shard_connection::disconnect() {

0 commit comments

Comments
 (0)