]> granicus.if.org Git - icinga2/commitdiff
Fix hanging API connections
authorSimon Murray <spjmurray@yahoo.co.uk>
Tue, 21 Jun 2016 14:46:53 +0000 (15:46 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 22 Jun 2016 07:25:00 +0000 (09:25 +0200)
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>
lib/base/tcpsocket.cpp

index b438dcd732454569bbb668a2480aa4aec51cae4e..02b105441262f438e0ed7cb49fb21125c786dc01 100644 (file)
@@ -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) {