From 957c6c971e859abe2752d656df620c985e157413 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 8 Feb 2017 10:56:53 -0500 Subject: [PATCH] Fix issues with idle behavior Some BMCs appear to expire a session within 30 seconds, unfortunately. Also, be careful to always fire events, even if the remote has gone away. Change-Id: I1b57fa8841ca19c77d36abe3ccc5bf877e09945a --- pyghmi/ipmi/private/session.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index 5c1d9547..87d0ac1e 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -65,6 +65,9 @@ MAX_BMCS_PER_SOCKET = 64 # no more than this many BMCs will share a socket # this could be adjusted based on rmem_max # value, leading to fewer filehandles +MAX_IDLE = 29 # maximum time to allow idle, more than this and BMC may assume + # incorrect idle + def define_worker(): class _IOWorker(threading.Thread): @@ -737,10 +740,10 @@ class Session(object): self.awaitresponse(retry, waitall) lastresponse = self.lastresponse self.incommand = False - if retry and lastresponse is None: - raise exc.IpmiException('Session no longer connected') while self.evq: self.evq.popleft().set() + if retry and lastresponse is None: + raise exc.IpmiException('Session no longer connected') return lastresponse def _send_ipmi_net_payload(self, netfn=None, command=None, data=(), code=0, @@ -867,7 +870,7 @@ class Session(object): if (self in Session.keepalive_sessions and not needskeepalive and not self._customkeepalives): Session.keepalive_sessions[self]['timeout'] = _monotonic_time() + \ - 50 + (random.random() * 4.9) + MAX_IDLE - (random.random() * 4.9) self._xmit_packet(retry, delay_xmit=delay_xmit, timeout=timeout) def _ipmi15authcode(self, payload, checkremotecode=False): @@ -979,7 +982,7 @@ class Session(object): Session.keepalive_sessions[self] = {} Session.keepalive_sessions[self]['ipmisession'] = self Session.keepalive_sessions[self]['timeout'] = _monotonic_time() + \ - 50 + (random.random() * 4.9) + MAX_IDLE - (random.random() * 4.9) self.onlogon({'success': True}) def _get_session_challenge(self): @@ -1106,7 +1109,7 @@ class Session(object): # until incommand is no longer the case if parms['timeout'] < curtime and not session._isincommand(): cls.keepalive_sessions[session]['timeout'] = \ - _monotonic_time() + 50 + (random.random() * 4.9) + _monotonic_time() + MAX_IDLE - (random.random() * 4.9) sessionstokeepalive.append(session) for session in sessionstokeepalive: session._keepalive()