From ec62027342736c19f21ce684f8f06e503b534e93 Mon Sep 17 00:00:00 2001 From: Frezzle Date: Tue, 11 Oct 2016 17:40:06 +0100 Subject: [PATCH 1/2] CA-214653: Work-around for XC reconnecting to proxy server with new wrong credentials Normally, a heartbeat is done every 15 seconds by getting the server time, and starts as soon as connection to host is established, but if an error occurs XC retries once more in another 15 seconds before actually closing the connection to the host. Now, if a 407 Proxy Authentication Required error occurs on the initial heartbeat then XC does not retry again in 15 seconds; it will close the connection immediately. The disconnection was instant to up to 2 seconds, depending on time taken to get server time (testing with FreeProxy was ~instant and CCProxy was ~2 seconds). This is only a work-around, as the exact reason for this behaviour is still unknown. Signed-off-by: Frezzle --- XenModel/Network/Heartbeat.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/XenModel/Network/Heartbeat.cs b/XenModel/Network/Heartbeat.cs index b66177398..ccca4b447 100644 --- a/XenModel/Network/Heartbeat.cs +++ b/XenModel/Network/Heartbeat.cs @@ -148,6 +148,23 @@ namespace XenAdmin.Network HandleConnectionLoss(); return; } + catch (WebException exn) + { + log.Error(exn); + if (((HttpWebResponse)exn.Response).StatusCode == HttpStatusCode.ProxyAuthenticationRequired) // work-around for CA-214653 + { + log.DebugFormat("Heartbeat for {0} has failed due to {1} credentials; closing the main connection", + session == null ? "null" : session.Url, + session.proxy.Proxy.Credentials == null ? "missing" : "incorrect"); + connection.Interrupt(); + DropSession(); + } + else + { + HandleConnectionLoss(); + } + return; + } catch (Exception exn) { log.Error(exn); From 2f7a938643e2a208093dbc7413fd304d881c0dee Mon Sep 17 00:00:00 2001 From: Frezzle Date: Wed, 12 Oct 2016 19:25:38 +0100 Subject: [PATCH 2/2] [CA-214653] Code clean-up following code review Signed-off-by: Frezzle --- XenModel/Network/Heartbeat.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/XenModel/Network/Heartbeat.cs b/XenModel/Network/Heartbeat.cs index ccca4b447..95920973e 100644 --- a/XenModel/Network/Heartbeat.cs +++ b/XenModel/Network/Heartbeat.cs @@ -131,7 +131,7 @@ namespace XenAdmin.Network // Now that we've successfully received a heartbeat, reset our 'second chance' for the server to timeout if (retrying) - log.DebugFormat("Heartbeat for {0} has come back", session == null ? "null" : session.Url); + log.DebugFormat("Heartbeat for {0} has come back", session.Url); retrying = false; } catch (TargetInvocationException exn) @@ -146,16 +146,19 @@ namespace XenAdmin.Network log.Error(exn); } HandleConnectionLoss(); - return; } catch (WebException exn) { log.Error(exn); if (((HttpWebResponse)exn.Response).StatusCode == HttpStatusCode.ProxyAuthenticationRequired) // work-around for CA-214653 { - log.DebugFormat("Heartbeat for {0} has failed due to {1} credentials; closing the main connection", - session == null ? "null" : session.Url, - session.proxy.Proxy.Credentials == null ? "missing" : "incorrect"); + if (session == null) + log.Debug("Heartbeat has failed due to null session; closing the main connection"); + else if (session.proxy.Proxy.Credentials == null) + log.DebugFormat("Heartbeat for {0} has failed due to missing credentials; closing the main connection", session.Url); + else + log.DebugFormat("Heartbeat for {0} has failed due to incorrect credentials; closing the main connection", session.Url); + connection.Interrupt(); DropSession(); } @@ -163,13 +166,11 @@ namespace XenAdmin.Network { HandleConnectionLoss(); } - return; } catch (Exception exn) { log.Error(exn); HandleConnectionLoss(); - return; } }