Skip to content

Commit 2a27e54

Browse files
committed
Handle non-blocking I/O errors on Unix socket client connect
1 parent c7d2b57 commit 2a27e54

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
@@ -277,16 +277,27 @@ int shard_connection::connect(struct connect_info* addr) {
277277
// call connect
278278
m_connection_state = conn_in_progress;
279279

280-
if (bufferevent_socket_connect(m_bev,
281-
m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr,
282-
m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == -1) {
280+
while (true) {
281+
if (bufferevent_socket_connect(m_bev,
282+
m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr,
283+
m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == 0) {
284+
return 0;
285+
}
286+
287+
if (errno == EINPROGRESS) {
288+
return 0;
289+
}
290+
291+
if (errno == EAGAIN || errno == EWOULDBLOCK) {
292+
// resource temporarily unavailable; try again
293+
continue;
294+
}
295+
283296
disconnect();
284297

285298
benchmark_error_log("connect failed, error = %s\n", strerror(errno));
286299
return -1;
287300
}
288-
289-
return 0;
290301
}
291302

292303
void shard_connection::disconnect() {

0 commit comments

Comments
 (0)