Skip to content

Commit

Permalink
Fix hanging API connections
Browse files Browse the repository at this point in the history
There was a problem identified where an upstream API connection was found hanging waiting
for a TLS handshake to complete.  Seeingly the TCP connection was ESTABLISHED locally but
not cleanly terminated remotely.  The Socket events layer never triggered the TLS handshake
oddly.  This however enables TCP keep alive packets to detect broken connections, raising
EPOLLERR and breaking the deadlock condition so that the agent will attempt to reconnect
at a later time.

fixes #12003

Signed-off-by: Gunnar Beutner <gunnar.beutner@netways.de>
  • Loading branch information
spjmurray authored and gunnarbeutner committed Jun 22, 2016
1 parent ba24f7b commit e3645aa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/base/tcpsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ void TcpSocket::Connect(const String& node, const String& service)
continue;
}

int optval = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) != 0) {
#ifdef _WIN32
error = WSAGetLastError();
#else /* _WIN32 */
error = errno;
#endif /* _WIN32 */
Log(LogWarning, "TcpSocket")
<< "setsockopt() unable to enable TCP keep-alives with error code " << rc;
}

rc = connect(fd, info->ai_addr, info->ai_addrlen);

if (rc < 0) {
Expand Down

0 comments on commit e3645aa

Please sign in to comment.