1
0
Fork 0

periodically recheck socket validity/connectivity for sockets that loop around poll() every 20s (#4535)

This commit is contained in:
Jan 2018-02-08 08:40:52 +01:00 committed by GitHub
parent cf0d575246
commit 4e99113bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -167,7 +167,7 @@ void GeneralClientConnection::disconnect() {
/// @brief prepare connection for read/write I/O
////////////////////////////////////////////////////////////////////////////////
bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool isWrite) const {
bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool isWrite) {
// wait for at most 0.5 seconds for poll/select to complete
// if it takes longer, break each poll/select into smaller chunks so we can
// interrupt the whole process if it takes too long in total
@ -178,6 +178,7 @@ bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool
#ifdef TRI_HAVE_POLL_H
// Here we have poll, on all other platforms we use select
double sinceLastSocketCheck = start;
bool nowait = (timeout == 0.0);
int towait;
if (timeout * 1000.0 > static_cast<double>(INT_MAX)) {
@ -221,6 +222,16 @@ bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool
if (towait <= 0) {
break;
}
// periodically recheck our socket
if (end - sinceLastSocketCheck >= 20.0) {
sinceLastSocketCheck = end;
if (!checkSocket()) {
// socket seems broken. now escape this loop
break;
}
}
start = end;
continue;
}

View File

@ -170,7 +170,7 @@ class GeneralClientConnection {
/// @brief prepare connection for read/write I/O
//////////////////////////////////////////////////////////////////////////////
bool prepare(TRI_socket_t socket, double timeout, bool isWrite) const;
bool prepare(TRI_socket_t socket, double timeout, bool isWrite);
//////////////////////////////////////////////////////////////////////////////
/// @brief check whether the socket is still alive