Skip to content

Commit

Permalink
HPCC-30431 Roxie incorrectly sees client connection as closed
Browse files Browse the repository at this point in the history
Signed-off-by: M Kelly <[email protected]>
  • Loading branch information
mckellyln committed Sep 26, 2024
1 parent 50ed84f commit 978bcb1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions system/jlib/jsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,8 +2248,10 @@ bool CSocket::check_connection()
return false;

// This routine is for TCP stream sockets.
// It is the callers responsibility to ensure this is called
// in a thread-safe manner, while no other threads are reading.
// if another thread called sock->read() between the
// wait_read() and recv() calls below then the
// wait_read() might return EWOULDBLOCK and we would
// assume then the socket is still connected and ok.

// wait_read() returns = 0 - socket ok atm
// returns < 0 - error, assume closed
Expand All @@ -2263,11 +2265,16 @@ bool CSocket::check_connection()
int retrycount = 100;
char buffer;

int recvFlags = MSG_PEEK;
#ifndef _WIN32
recvFlags |= MSG_DONTWAIT;
#endif

EintrRecv:
rc = recv(sock, &buffer, sizeof(buffer), MSG_PEEK);
rc = recv(sock, &buffer, sizeof(buffer), recvFlags);

// recv() returns = 0 - socket eof (closed)
// returns < 0 - error, assume closed
// returns < 0 - and errno not EWOULDBLOCK/EAGAIN, assume closed
// returns > 0 - socket ok atm
if (rc == 0)
return false;
Expand All @@ -2279,6 +2286,8 @@ bool CSocket::check_connection()
LOGERR2(err,7,"recv EINTR retrying");
goto EintrRecv;
}
else if ((err==EWOULDBLOCK) || (err==EAGAIN))
return true;
else
return false;
}
Expand Down

0 comments on commit 978bcb1

Please sign in to comment.