483b06
From bdaf584ef5ebcae08e86142ceb80ebe56ac11fa3 Mon Sep 17 00:00:00 2001
483b06
From: Christian Heimes <cheimes@redhat.com>
483b06
Date: Mon, 20 Mar 2017 08:47:51 +0100
483b06
Subject: [PATCH] Add debug logging for keep-alive
483b06
483b06
Signed-off-by: Christian Heimes <cheimes@redhat.com>
483b06
Reviewed-By: Tomas Krizek <tkrizek@redhat.com>
483b06
---
483b06
 ipalib/rpc.py | 21 ++++++++++++++++++++-
483b06
 1 file changed, 20 insertions(+), 1 deletion(-)
483b06
483b06
diff --git a/ipalib/rpc.py b/ipalib/rpc.py
483b06
index 8d587180a65bd06b644c6df23ac9fb26eb7e97dd..38321d17cf2c9529738aa45cc44bbd38b08b032b 100644
483b06
--- a/ipalib/rpc.py
483b06
+++ b/ipalib/rpc.py
483b06
@@ -79,6 +79,13 @@ except ImportError:
483b06
     from xmlrpc.client import (Binary, Fault, DateTime, dumps, loads, ServerProxy,
483b06
             Transport, ProtocolError, MININT, MAXINT)
483b06
 
483b06
+# pylint: disable=import-error
483b06
+if six.PY3:
483b06
+    from http.client import RemoteDisconnected
483b06
+else:
483b06
+    from httplib import BadStatusLine as RemoteDisconnected
483b06
+# pylint: enable=import-error
483b06
+
483b06
 
483b06
 if six.PY3:
483b06
     unicode = str
483b06
@@ -531,6 +538,7 @@ class SSLTransport(LanguageAwareTransport):
483b06
         host, self._extra_headers, _x509 = self.get_host_info(host)
483b06
 
483b06
         if self._connection and host == self._connection[0]:
483b06
+            root_logger.debug("HTTP connection keep-alive (%s)", host)
483b06
             return self._connection[1]
483b06
 
483b06
         conn = create_https_connection(
483b06
@@ -540,6 +548,7 @@ class SSLTransport(LanguageAwareTransport):
483b06
             tls_version_max=api.env.tls_version_max)
483b06
 
483b06
         conn.connect()
483b06
+        root_logger.debug("New HTTP connection (%s)", host)
483b06
 
483b06
         self._connection = host, conn
483b06
         return self._connection[1]
483b06
@@ -686,8 +695,18 @@ class KerbTransport(SSLTransport):
483b06
                 return self.parse_response(response)
483b06
         except gssapi.exceptions.GSSError as e:
483b06
             self._handle_exception(e)
483b06
-        except BaseException:
483b06
+        except RemoteDisconnected:
483b06
+            # keep-alive connection was terminated by remote peer, close
483b06
+            # connection and let transport handle reconnect for us.
483b06
+            self.close()
483b06
+            root_logger.debug("HTTP server has closed connection (%s)", host)
483b06
+            raise
483b06
+        except BaseException as e:
483b06
+            # Unexpected exception may leave connections in a bad state.
483b06
             self.close()
483b06
+            root_logger.debug("HTTP connection destroyed (%s)",
483b06
+                              host, exc_info=True)
483b06
+            raise
483b06
 
483b06
     if six.PY3:
483b06
         def __send_request(self, connection, host, handler, request_body, debug):
483b06
-- 
483b06
2.12.1
483b06