From 9d40f56c6384d04a5f0fb22e5b97530c0164e0b2 Mon Sep 17 00:00:00 2001 From: David Scott Date: Mon, 28 Apr 2014 17:34:50 +0100 Subject: [PATCH] XenServer: when we receive a SESSION_INVALID, automatically log back in It's possible for a session to be expired by the server, due to inactivity. In this case we should log back in. This also works around a problem where some other thread appears to be logging out our session, even though we're still using it (for event.from) Signed-off-by: David Scott --- .../xen/resource/XenServerConnectionPool.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerConnectionPool.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerConnectionPool.java index e8bc741c4af8..ccccaf38d7c1 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerConnectionPool.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerConnectionPool.java @@ -451,24 +451,27 @@ protected Map dispatch(String methodcall, Object[] methodparams) throws XmlRpcE return super.dispatch(methodcall, methodparams); } - try { - return super.dispatch(methodcall, methodparams); - } catch (Types.SessionInvalid e) { - s_logger.debug("Session is invalid for method: " + methodcall + " due to " + e.toString()); - removeConnect(_poolUuid); - throw e; - } catch (XmlRpcClientException e) { - s_logger.debug("XmlRpcClientException for method: " + methodcall + " due to " + e.toString()); - removeConnect(_poolUuid); - throw e; - } catch (XmlRpcException e) { - s_logger.debug("XmlRpcException for method: " + methodcall + " due to " + e.toString()); - removeConnect(_poolUuid); - throw e; - } catch (Types.HostIsSlave e) { - s_logger.debug("HostIsSlave Exception for method: " + methodcall + " due to " + e.toString()); - removeConnect(_poolUuid); + while (true) { + try { + return super.dispatch(methodcall, methodparams); + } catch (Types.SessionInvalid e) { + s_logger.warn("Session is invalid for method: " + methodcall + " logging back in"); + // This will reset the session reference cached inside the Connection + Session.loginWithPassword(this, _username, _password.peek(), APIVersion.latest().toString()); + continue; + } catch (XmlRpcClientException e) { + s_logger.debug("XmlRpcClientException for method: " + methodcall + " due to " + e.toString()); + removeConnect(_poolUuid); + throw e; + } catch (XmlRpcException e) { + s_logger.debug("XmlRpcException for method: " + methodcall + " due to " + e.toString()); + removeConnect(_poolUuid); + throw e; + } catch (Types.HostIsSlave e) { + s_logger.debug("HostIsSlave Exception for method: " + methodcall + " due to " + e.toString()); + removeConnect(_poolUuid); throw e; + } } } }